Csharp/CSharp Tutorial/Regular Expression/Regex Split

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

RegEx Split

using System;
using System.Text;
using System.Text.RegularExpressions;
    public class Tester
    {
        static void Main()
        {
            string s1 = "One,Two,Three YourName, Inc.";
            StringBuilder sBuilder = new StringBuilder();
            int id = 1;
            foreach (string subStr in Regex.Split(s1, " |, |,"))
            {
                sBuilder.AppendFormat("{0}: {1}\n", id++, subStr);
            }
            Console.WriteLine("{0}", sBuilder);
        }
    }