If you need to search for a character you can use the strchr
function, like this:
char* pPosition = strchr(pText, '|');
pPosition
will be NULL
if the given character has not been found. For example:
puts(strchr("field1|field2", '|'));
Will output: "|field2". Note that strchr
will perform a forward search, to search backward you can use the strrchr
. Now imagine (just to provide an example) that you have a string like this: "variable:value|condition". You can extract the value field with:
char* pValue = strrchr(strchr(pExpression, '|'), ':') + 1;
If what you want is the index of the character inside the string take a look to this post here on SO. You may need something like IndexOfAny()
too, here another post on SO that uses strnspn
for this.
Instead if you're looking for a string you can use the strstr
function, like this:
char* pPosition = strstr(pText, "text to find");