您的位置:首页 > 其它

按照指定的字符分割字符串形成字符数组

2012-02-22 09:25 441 查看
using System;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = "ab,cd,ef|12*34";
string[] strs = str.Split(',','|','*');// 按照指定的字符分割字符串形成字符数组

foreach (string c in strs)
{
Console.WriteLine("|{0}|", c);
}

Console.WriteLine("-----------------------------");

string str2 = "ab,cd,,ef|12*34";
string[] strs2 = str2.Split(',', '|', '*');// 无法去处空白(有空格不算)字符串

foreach (string c in strs2)
{
Console.WriteLine("|{0}|", c);
}

Console.WriteLine("-----------------------------");

string str3 = "ab,cd,,ef|12*34";
string[] strs3 = str3.Split(new char[] { ',', '|', '*' }, StringSplitOptions.RemoveEmptyEntries);// 去处空白(有空格不算字符串

foreach (string c in strs3)
{
Console.WriteLine("|{0}|", c);
}

Console.ReadKey();
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: