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();
}
}
}
按照指定的字符分割字符串形成字符数组
最新推荐文章于 2021-06-08 18:38:03 发布