您的位置:首页 > 其它

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

2012-04-17 13:29 316 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: