能不能把一个字符串以其中的空格为分隔符分成一个字符串数组,有没有直接实现的语句
2个回答
2012-07-11
展开全部
using System;
publicclass SplitTest {
publicstaticvoid Main() {
string words = "This is a list of words, with: a bit of punctuation" +
"\tand a tab character.";
string [] split = words.Split(new Char [] {' ', ',', '.', ':', '\t' });
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// and// a// tab// character
publicclass SplitTest {
publicstaticvoid Main() {
string words = "This is a list of words, with: a bit of punctuation" +
"\tand a tab character.";
string [] split = words.Split(new Char [] {' ', ',', '.', ':', '\t' });
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// and// a// tab// character
参考资料: http://msdn.microsoft.com/zh-cn/library/b873y76a.aspx
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询