NetLover

导航

String.Split 方法 (Char[])使用示例

 

public string[] Split(
	params char[] separator
)

下面的示例演示如何通过将空白和标点符号视为分隔符来提取文本块中的各个单词。

 

using System;

public class SplitTest {
    public static void Main() {

        string words = "This is a list of words, with: a bit of punctuation.";

        string [] split = words.Split(new Char [] {' ', ',', '.', ':'});

        foreach (string s in split) {

            if (s.Trim() != "")
                Console.WriteLine(s);
        }
    }
}
// The example displays the following output to the console:
//       This
//       is
//       a
//       list
//       of
//       words
//       with
//       a
//       bit
//       of
//       punctuation

posted on 2012-04-17 13:29  NetLover  阅读(437)  评论(0编辑  收藏  举报