Mikroelektronika MIKROE-442 Datenbogen

Seite von 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
679
strspn
Prototype
sub function strspn(dim byref s1, s2 as string) as word
Description The function searches the string 
s1
 for characters not found in the 
s2
 string.
The function returns the index of first character located in 
s1
 that does not match a character in 
s2
. If 
the first character in 
s1
 does not match a character in 
s2
, a value of 0 is returned. If all characters in 
s1
 are found in 
s2
, the length of 
s1
 is returned (not including the terminating null character).
Example
txt = “mikroElektronika”
txt_sub = “mikr”
res = strspn(txt,txt_sub)  ‘ routne returns 4
strncmp
Prototype
sub  function  strncmp(dim  byref  s1,  s2  as  string,  dim  len  as  byte)  as 
integer
Description The function lexicographically compares the first 
len
 characters 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 first pair 
of words that differ in the strings being compared (within first 
len
 words).
Example
txt = “mikroElektronika”
txt_sub = “mikr”
res  =  strncmp(txt_sub,txt,3)    ‘  compares  the  first  3  characters  from  the 
string ‘txt’ with the sting ‘txt_sub’ and returns a difference
strstr
Prototype
sub function strstr(dim byref s1, s2 as string) as word
Description The function locates the first occurrence of the string 
s2
 in the string 
s1
 (excluding the terminating 
null character).
The function returns a number indicating the position of the first occurrence of 
s2
 in 
s1
; if no string was 
found, the function returns 0xFFFF. If 
s2
 is a null string, the function returns 
0
.
Example
txt = “mikroElektronika”
txt_sub = “mikr”
res = strstr(txt_sub,txt)