- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- namespace Study
- {
- public static class Program3
- {
- static void Main(string[] args)
- {
- Proccess(@"13212345671,13312345672, 13412345674
- 13212345674,");
- Proccess("");
- Proccess(null);
- Console.Read();
- }
- public static void Proccess(string str)
- {
- //双问号保证 null 值不会异常
- //StringSplitOptions.RemoveEmptyEntries 会移除 string.Empty 空串, 但对于空格无能为力
- //' '将按空格来切分,所以不再有空格出现
- string[] arr = (str ?? string.Empty).Split(new char[] { ',', '\t', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- Console.WriteLine("本次切分后数组的长度为:{0}", arr.Length);
- int i = 1;
- foreach (string s in arr)
- {
- Console.WriteLine("{0}:{1}", (i++).ToString(), s);
- }
- }
- }
- }