1 private void button1_Click(object sender, EventArgs e) 2 { 3 string aaaa = "NACA-1-4-0008"; 4 string[] indexlist = aaaa.Split('-'); 5 } 6 7 private void button2_Click(object sender, EventArgs e) 8 { 9 string str = "aaajSbbbjscccJS";10 string[] sArray = Regex.Split(str, "js", RegexOptions.IgnoreCase);11 12 string str1 = "technology";13 char[] separator = { 'o' };14 string[] arr = str1.Split(separator);15 }16 17 private void button3_Click(object sender, EventArgs e)18 {19 string str = "aaajbbbscccjdddseee";20 string[] sArray = str.Split(new char[2] { 'j', 's' });21 }22 23 string words = "1,2.3,,4";24 private void button4_Click(object sender, EventArgs e)25 {26 string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素27 string[] split1 = words.Split(new Char[] { ',', '.' }, 3, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 28 string[] split2 = words.Split(new Char[] { ',', '.' }, 4, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 29 string[] split3 = words.Split(new Char[] { ',', '.' }, 5, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 30 string[] split4 = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 31 }32 33 private void button5_Click(object sender, EventArgs e)34 {35 string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素36 string[] split1 = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素37 }38 39 private void button6_Click(object sender, EventArgs e)40 {41 string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素42 string[] split1 = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 43 }44 45 private void button7_Click(object sender, EventArgs e)46 {47 string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素48 string[] split1 = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 49 }50 51 52 //需要注意的是没有重载函数public string[] Split(string[] separator),53 //所以我们不能像VB.NET那样使用words.Split(","),而只能使用words.Split(',')