Find character in string

Syntax

int findc(string char [from])
int findcr(string char [fromr])
int findcs(string charset [from])
int findcn(string charset [from])

 

Parameters

string - string to search in.

char - character to find. Integer character code or single-character string.

charset - characters to find or skip. String.

from - 0-based character index from which to start search. Default: 0.

fromr - 0-based character index from which to start search towards beginning. Default: -1 (string length).

 

Remarks

Finds character char in string. If not found, returns -1.

 

findc returns 0-based index of char.

findcr returns 0-based index of char, but searches from right to left.

findcs returns 0-based index of first character that is in charset.

findcn returns 0-based index of first character that is not in charset.

 

In Unicode mode, string can contain any characters, but char must be an ASCII character, and charset must contain only ASCII characters. To find an Unicode character, use find.

 

Examples

str s = "c:\windows\calc.exe"
int i = findc(s ':')
 now i is 1
i = findcr(s '\')
 now i is 10
i = findcs(s ":\/." 11)
 now i is 15