Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seperating the characters and numbers in a string

Status
Not open for further replies.

nickmollberg

Programmer
Aug 2, 2004
29
US
Hello,
This is remarkably simple I'm sure, but I need to seperate out the contents of a string.

The string is "TestString1"
And I need to parse this out into the characters, and the number.
So, I'd like to end up with "TestString" and "1"

This Could be any combination of text, followed by a number, ie. customer88, testuser2, tim9, oo9.
But, it will always be characters, followed by a number.

Thanks!
 
Hey

you may try:

Code:
   string test = "TESTSTRING1"
   string charstr = "";
   string numstr = "";
   foreach (char c in test)
   {
   	if (char.IsNumber(c) == true)
   	{
   		numstr += c;
   	}
       else
       {
            charstr += c;
       }
   }

Note: This will pull any numbers out of the string, so you may have to tweak it a bit.

Good luck,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top