home *** CD-ROM | disk | FTP | other *** search
- PROGRAM test;
-
- {This is a test program for the additional string functions implemented in
- the UNIT strings.
-
- ExtractForCount
-
- Declaration
- target_str := ExtractForCount(source_string, sizeof(target_string, start_pos)
-
- Operation
- This FUNCTION will move 'n' characters from the source string into the
- target string starting from the character in the source string pointed
- to by start_pos). Once the characters have been moved into the target
- string they are deleted from the source string.
-
- ExtractToChar
-
- Declaration
- target_str := ExtractToChar(source_str, sizeof(target_str), search_char)
-
- Operation
- This FUNCTION will move characters from the source string into the target
- string UNTIL the a character matching search_char is encountered. When
- the search_char is matched character movement stops (movement does not
- include the search_char). The characters that were moved are deleted
- from the source string.
-
- Translate
-
- Declaration
- Translate(str_to_translate, translate_table);
-
- Operation
- This PROCEDURE will translate the string indicated by str_to_translate
- according to the 256 character translation table specified by the
- second operand. The translation table is assumed to be 256 bytes in
- length and must be setup by the caller.
-
- For each byte in the str_to_translate, the character is extracted and
- it's logical value is added to the starting address of the translation
- table. The table character pointed by that sum is used to replace the
- original character.
-
- PadLeft
-
- Declaration
- PadLeft(string, sizeof(string), new_length, pad_char);
-
- Operation
- This PROCEDURE will insert pad_char into the 1st position of string
- until the length of string is equal to new_length or the string
- reaches it's maximum size.
-
-
- PadRight
-
- Declaration
- PadRight(string, sizeof(string), new_length, pad_char);
-
- Operation
- This PROCEDURE will insert pad_char into the LAST position of string
- until the length of string is equal to new_length or the string
- reaches it's maximum size.
-
- Uppercase
-
- Declaration
- target_str := Uppercase (source_str);
-
- Operation
- This FUNCTION will convert each character within the range of a..z in
- the source_string into it's corresponding uppercase character and place
- it into the target_string.
-
- StringOf
-
- Declaration
- target_str := StringOf (pad_char, string_len);
-
- Operation
- This FUNCTION will create a string containing string_len occurances of
- pad_char. The original contents of the string are ignored and the user
- is assumed to know what he/she is doing as there is no check for excedding
- the maximum length of the string.
- }
-
-
-
-
- uses strings,
- crt;
-
-
-
- VAR
- str0 : STRING[20];
- v1 : STRING[20];
- str1 : STRING[20];
- v2 : STRING[20];
- str2 : STRING[20];
- v3 : STRING[20];
- str3 : STRING[20];
- v4 : STRING[20];
- table : STRING[255];
- i : integer;
-
-
-
- BEGIN
- v1 := '12345678901234567890';
- v2 := v1;
- v3 := v1;
- v4 := v1;
- str1 := 'this is STRING 1';
- str2 := '*';
- str3 := 'this is STRING 3';
- WRITELN;
- WRITELN('Testing PadLeft............');
- WRITELN;
- REPEAT
- padleft(str2,sizeof(str2),(length(str2)+1),' ');
- IF (v2 <> '12345678901234567890') OR
- (v3 <> '12345678901234567890') THEN BEGIN
- WRITELN('Error: boundary validation failed');
- HALT;
- END;
- WRITELN('l str2 = ',length(str2):2,' str2 = [',str2,']');
- UNTIL length(str2) = 20;
- DELAY(3000);
-
-
- WRITELN;
- WRITELN('Testing ExtractForCount.......');
- WRITELN;
- REPEAT
- str3 := ExtractForCount(str2,sizeof(str3),1);
- IF (v2 <> '12345678901234567890') OR
- (v3 <> '12345678901234567890') THEN BEGIN
- WRITELN('Error: boundary validation failed');
- HALT;
- END;
- IF (v3 <> '12345678901234567890') OR
- (v4 <> '12345678901234567890') THEN BEGIN
- WRITELN('Error: boundary validation failed');
- HALT;
- END;
- WRITE('l str3 = ',length(str3):2,' str3 = [',str3,']');
- WRITELN('l str2 = ',length(str2):2,' str2 = [',str2,']');
- UNTIL length(str2) = 0;
- DELAY(3000);
-
-
- WRITELN;
- WRITELN('Testing ExtractForCount.......');
- WRITELN;
- str2 := '*';
- padleft(str2,sizeof(str2),20,' ');
- str3 := ExtractForCount(str2,sizeof(str3),25);
- IF (v3 <> '12345678901234567890') OR
- (v4 <> '12345678901234567890') THEN BEGIN
- WRITELN('Error: boundary validation failed');
- HALT;
- END;
- WRITE('l str3 = ',length(str3):2,' str3 = [',str3,']');
- WRITELN('l str2 = ',length(str2):2,' str2 = [',str2,']');
- DELAY(3000);
-
-
- str2 := '1 2 3 4 5 6 7 8 9';
- WRITELN;
- WRITELN('Testing ExtractToChar.....');
- WRITELN;
- REPEAT
- str3 := ExtractToChar(str2,sizeof(str3),' ');
- delete(str2,1,1);
- IF (v3 <> '12345678901234567890') OR
- (v4 <> '12345678901234567890') THEN BEGIN
- WRITELN('Error: boundary validation failed');
- HALT;
- END;
- WRITE('l str3 = ',length(str3):2,' str3 = [',str3,']');
- WRITELN('l str2 = ',length(str2):2,' str2 = [',str2,']');
- UNTIL length(str3) = 0;
- DELAY(3000);
-
-
- str2 := '!';
- WRITELN;
- WRITELN('Testing PadRight......');
- WRITELN;
- REPEAT
- padright(str2,sizeof(str2),(length(str2)+1),'*');
- IF (v2 <> '12345678901234567890') OR
- (v3 <> '12345678901234567890') THEN BEGIN
- WRITELN('Error: boundary validation failed');
- HALT;
- END;
- WRITELN('l str2 = ',length(str2):2,' str2 = [',str2,']');
- UNTIL length(str2) = 15;
- DELAY(3000);
-
-
- FOR i := 0 to 255 DO
- table[i] := CHR(ORD(i));
- str0 := '..../....1..../....2';
- table[ORD('.')] := ' ';
- WRITELN;
- WRITELN('Testing Translate.....');
- WRITELN;
- WRITELN('Original STRING = ',str0);
- translate(str0, table);
- WRITELN('Translated STRING = ',str0);
- end.