str_chr(STRING*, var pos, var char)

Finds the position of a character in a string from a certain start position.

Parameters:

STRING* - string pointer to be searched.
pos - position to start searching (1 for the first character). When negative, the string is searched towards its begin, otherwise towards its end.
char - ASCII value of the character to be searched for.

Returns:

Position of the first occurrence of the character (1 for the first character), or 0 when the character was not found.

Speed:

Fast

Example (lite-C):

#include <strio.c> // for str_cut
...
// get a certain filename from a string
STRING* str = "test1.log test2.scr test3.c test4.wdl...";
var pos = str_stri(str,".scr"); // find the first ".scr" occurrence
if (pos) {
   var blank = str_chr(str,-pos,' '); // find the blank before the file name
   STRING* filename = str_cut(NULL,str,blank+1,pos+3);
}

See also:

str_cpy, str_cat, str_cmp, str_cmpi, str_cmpni, str_len, str_clip, str_trunc, strio.c 

► latest version online