An example of Regex.Split in C#

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 192
var inputText = @"UserName: RNA Team
Country: India";
inputText
.Split(new string[] { "\r\n" }, StringSplitOptions.None)
.Where(s => s.IndexOf(':') != -1)
.Select(s => s.Trim())
.ToList()
.ForEach(line =>
{
var txt = Regex.Split(line, @":");
Console.WriteLine("{0} {1}", txt[0], txt[1]);
});

Result
----------

UserName RNA Team
Country India
Forum DNF
Section Code

Comments or Responses

Login to post response