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 Code |
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 Code |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amitesh VermaRank #2,535 · 552 reputationPosted Aug 21, 2016, 11:35 PM EDT
using System.Text.RegularExpressions; Regex re = new Regex(@"([a-zA-Z]+)(\d+)"); Match result = re.Match(input); string alphaPart = result.Groups[1].Value; string numberPart = result.Groups[2].Value;Vinay SinghRank #604 · 4K reputationPosted Aug 22, 2016, 12:49 AM EDT
Regex rgx = new Regex("[^a-zA-Z-]");
Regex rgx = new Regex("[^0-9-]");
Bhuvan PandeyRank #2,683 · 519 reputationPosted Aug 22, 2016, 12:52 AM EDT
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());
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 22, 2016, 1:04 AM EDT
ketan borsdiyaRank #2,258 · 624 reputationPosted Aug 22, 2016, 1:23 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Aug 22, 2016, 1:38 AM EDT