i have a string like this "1hyd2345". i need to seperate and store characters in one string.and numbers in another string, Example:my input is "1hyd2345" output:Location:hyd |
Loading
i have a string like this "1hyd2345". i need to seperate and store characters in one string.and numbers in another string, Example:my input is "1hyd2345" output:Location:hyd |
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bikesh SrivastavaPosted Aug 22, 2016, 5:38 AM
ketan borsdiyaPosted Aug 22, 2016, 5:23 AM
Rajeesh MenothPosted Aug 22, 2016, 5:04 AM
Bhuvan PandeyPosted Aug 22, 2016, 4:52 AM
Hi Shiva
User this code for your requirement.
string str = "1hyd2345";
StringBuilder sbStr = new StringBuilder();
StringBuilder sbNum = new StringBuilder();
foreach (var item in str)
{
if (char.IsLetter(item))
{
sbStr.Append(item);
}
if (char.IsNumber(item))
{
sbNum.Append(item);
}
}
Console.WriteLine("String :"+sbStr.ToString());
Console.WriteLine("Numbers :"+sbNum.ToString());
Vinay SinghPosted Aug 22, 2016, 4:49 AM
Regex rgx = new Regex("[^a-zA-Z-]");
Regex rgx = new Regex("[^0-9-]");
Amitesh VermaPosted Aug 22, 2016, 3:35 AM