Search This Blog

Loading...

May 20, 2011

How to Split String using Regx in Asp.net


Sponsored Links:

Basic things to be understood in

RegEx: "*" matches 0 or more patterns
  • "?" matches single character
  • "^" for ignoring matches.
  • "[]" for searching range patterns.
Regx belongs to using System.Text.RegularExpressions namespace
public static void ReverseString()
{
string s = "XyZ, AB,CC, D";
Regex regex = new Regex(@" |, ");
foreach (string sub in regex.Split(s))
{
Console.WriteLine("Word: {0}", sub);
}

}

How to call
static void Main(string[] args)
{
ReverseString();
Console.ReadLine();

Output
image

Follow by Email