udir
asked on
string search...
Hi,
I need to get a SubString from a string but the SubString length can change and also the start position of the SubString can be changed.
The string that starts with "<User" and ends withe "</User>" (i need to get the string between them).
Any Idea?
Thanks
I need to get a SubString from a string but the SubString length can change and also the start position of the SubString can be changed.
The string that starts with "<User" and ends withe "</User>" (i need to get the string between them).
Any Idea?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yourString.IndexOf("<User" ); returns the start location of this string in the string you are searching. So, say the whole string is:
<User>Tom</User>
Then startPos is returned as zero. By adding 5 to startPos, we are preparing to get the substring that starts with ">".
BTW:
startPos += 5;
is a shorthad way of writing:
startPos = startPos + 5;
If you wanted to skip the ">" too, and just get "Tom", change the 5 to a 6.
Jim
<User>Tom</User>
Then startPos is returned as zero. By adding 5 to startPos, we are preparing to get the substring that starts with ">".
BTW:
startPos += 5;
is a shorthad way of writing:
startPos = startPos + 5;
If you wanted to skip the ">" too, and just get "Tom", change the 5 to a 6.
Jim
ASKER
OK, Thanks a lot
My pleasure. Good luck.
Jim
Jim
ASKER
Thanks, just for knoledge :
what is the meanning of :
startPos += 5;