Get substring

Started by
1 comment, last by EIShadowDragon 19 years, 8 months ago
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"?
Advertisement
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:

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

Hey, thanks for your reply. It works now.

This topic is closed to new replies.

Advertisement