Sub string from string.

I'm having a bit of problems getting a piece of a string.

The string I have looks something like this.


50.184.xxx.xx:52240/7656119xxxxxxxxxx/John joined [windows/7656119xxxxxxxxxx]

Where x's can be different lengths, also John could be different name.

I have extracted the numbers from this string using find_first_of and find_last_of combinations by getting the "[" and "/" etc but I cannot figure out how to extract John. Any help would be greatly appreciated.
Last edited on
Use a for loop and keep checking for the \ (backslash).

For example, If your string name is a,
then
1
2
3
4
5
6
for(I=0;a[I]=='\';I++){
int z=a[I+1];
if((z>65 && z<90) || (z>97 && z<123)){
continue;
} 
 


Then make another loop to find 'joined'. If a[k]=='j' and a[k+1]=='o' ... ......
Then from a[k-2] till it reaches a '\' , it is the name.
do you need everything?

If I need every piece of information here I would make a class holding that connection information and then overload operator<<

If you just need John you could go to the second "/" and then read until the next space.

If that's not good enough (eg. if the user may have spaces in his name) you're fucked :)
Nah, jokes aside, if that's not good enough go to the last "[" (find_last_of) and then go back 8 steps, then search for the last "/" before "[" and go forth 1 step.
Everything between those two points is the Name of the person.

With that you should be able to do it ;)
Topic archived. No new replies allowed.