User manual

mikroPascal PRO for PIC32
MikroElektronika
589
strcmp
strcpy
strlen
strncat
Prototype
function strcmp(var s1, s2 : string) : integer;
Description The function lexicographically compares the contents of the strings s1 and s2 and returns a value
indicating their relationship:
Value Meaning
< 0 s1 “less than” s2
= 0 s1 “equal to” s2
> 0 s1 “greater than” s2
The value returned by the function is determined by the difference between the values of the rst pair
of words that differ in the strings being compared.
Example
txt := ‘mikroElektronika’;
res := strchr(txt, ‘E’); // routine will locate the character ‘E’ in the
‘txt’ string, and return the position of the character
Prototype
procedure strcpy(var s1, s2 : string);
Description The function copies the value of the string s2 to the string s1 and appends a null character to the end
of s1.
Example
txt := ‘mikroElektronika’;
txt_sub := ‘mikr’;
strcpy(txt,txt_sub); // copies string ‘txt_sub’ to ‘txt’
Prototype
function strlen(var s : string) : word;
Description The function returns the length, in words, of the string s. The length does not include the null terminating
character.
Example
txt := ‘mikroElektronika’;
res = strlen(txt); // calculates the length of the ‘txt’ string, result = 16
Prototype
procedure strncat(var s1, s2 : string; size : word);
Description The function appends at most size characters from the string s2 to the string s1 and terminates s1
with a null character. If s2 is shorter than the size characters, s2 is copied up to and including the null
terminating character.
Example
txt := ‘mikroElektronika’;
txt_sub := ‘mikr’;
txt[5] := 0;
strncat(txt,txt_sub,4); // routine appends rst 4 characters from the string
‘txt_sub’ at the place of rst null character in the ‘txt’ string