请问C#里面System.Text.RegularExpressions.Regex.Split()要怎么用?最好有一个范例
1个回答
展开全部
Regex regex = new Regex("-"); // Split on hyphens.string[] substrings = regex.Split("plum--pear");
foreach (string match in substrings)
{
Console.WriteLine("'{0}'", match);
}
// The method writes the following to the console:// 'plum'// ''// 'pear'
string input = "characters";
Regex regex = new Regex("");
string[] substrings = regex.Split(input);
Console.Write("{");
for(int ctr = 0; ctr < substrings.Length; ctr++)
{
Console.Write(substrings[ctr]);
if (ctr < substrings.Length - 1)
Console.Write(", ");
}
Console.WriteLine("}");
// The example produces the following output: // {, c, h, a, r, a, c, t, e, r, s, }
foreach (string match in substrings)
{
Console.WriteLine("'{0}'", match);
}
// The method writes the following to the console:// 'plum'// ''// 'pear'
string input = "characters";
Regex regex = new Regex("");
string[] substrings = regex.Split(input);
Console.Write("{");
for(int ctr = 0; ctr < substrings.Length; ctr++)
{
Console.Write(substrings[ctr]);
if (ctr < substrings.Length - 1)
Console.Write(", ");
}
Console.WriteLine("}");
// The example produces the following output: // {, c, h, a, r, a, c, t, e, r, s, }
参考资料: http://msdn.microsoft.com/zh-cn/library/ze12yx1d.aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询