Get substring
How would I go about retrieving a substring position ONLY if it is after another substring? For instance, take the example below:
if(val("100"))
{
}
How would I retrieve the first paranthesis after "val"?
Find the first occurence of "val" and add to that pointer the length of "val".Now you have a new string that starts after "val",so search for the first occurence of "(" in that string.
Something like this:
Something like this:
char str[255];char *str2;int strpos;strcpy(str,"val(100)");str2=strstr(str,"val")+strlen("val");//Find the first substringstr2=strstr(str2,"(");//Search only after that substringstrpos=(str2-str);//Get the position of second substring
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement