Link to home
Start Free TrialLog in
Avatar of udir
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
 
ASKER CERTIFIED SOLUTION
Avatar of JimBrandley
JimBrandley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of udir
udir

ASKER

Hi,
Thanks, just for knoledge :
what is the meanning of :
startPos += 5;
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
Avatar of udir

ASKER

OK, Thanks a lot
My pleasure. Good luck.

Jim