string find question
lets say the strings are of this format
<any chars here><static string here><any chars here>
e.g..
thisIsATeststatic735645646blahdyblah
45454346static735645646fgfdgfdgfdg
dgfdgfdgfgfsdgdfdstatic735645646dgfdgfdg
as you can see the static string is static735645646
how can i grab the bit *after* this static string?
so..
thisIsATeststatic735645646blahdyblah should give me blahdyblah
2nd one should give me fgfdgfdgfdg
3rd one should give me dgfdgfdg
hope you guys can help me out
[576 byte] By [
pouncer] at [2007-11-11 7:49:45]

# 1 Re: string find question
I would use find and substr from the string class..
//Find
string str1 = "thisIsATeststatic735645646blahdyblah";
string str2 = "static735645646";
size_type position = str1.find (str2,0);
cout << position << endl;
int length = (strlen(str1) - position);
//Substr
string str3 = str1.substr(position, length);
cout<<str3; //blahdyblah
I havent tested the code, but it should work :)
# 4 Re: string find question
actually its giving me erros now on
size_type position = str1.find (str2,0);
saying undeclared identifier size_type :S
# 5 Re: string find question
you need to #include <string> and qualify size_type with std::. Since size_type is just an alias for size_t, you can use size_t instead (not recommended, but it works on all compilers I can think of).
Danny at 2007-11-11 21:05:55 >

# 6 Re: string find question
you need to #include <string> and qualify size_type with std::. Since size_type is just an alias for size_t, you can use size_t instead (not recommended, but it works on all compilers I can think of).
Yes sorry didnt add that..
Thanks Danny :)