C#基础 string Split 用字符分割字符串,删除空白项
未删除空白项
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { string number = "0,,1..2,,3;;456789"; string[] strs = number.Split(new char[] { ',', '.', ';' }); foreach (var item in strs) { Console.WriteLine(item); } Console.ReadKey(); } } }
删除空白项 - StringSplitOptions.RemoveEmptyEntries
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { string number = "0,,1..2,,3;;456789"; string[] strs = number.Split(new char[] { ',', '.', ';' }, options: StringSplitOptions.RemoveEmptyEntries); foreach (var item in strs) { Console.WriteLine(item); } Console.ReadKey(); } } }
每天一点点。。。