c# 字符串转换为字符数组方法总结


1、单个字符分拆字符串



string str      = “testInfo1&*&testInfo2&*&testInfo3”; 
string[] strArr = str.split(‘*’);
//通过此函数将会产生3个字符串
strArr[0]  =   “testInfo1&”;
strArr[1]  =   “&testInfo2&”;
strArr[2]  =   “&testInfo3”;


2、通过多个不同的字符来拆分字符串

 
 strArr = str.split(new char[2]{’s’,’*’});
 
 strArr[0]  =   “te”;
 strArr[1]  =   “tInfo1&”;
 strArr[2]  =   “&te”;
 strArr[3]  =   “tInfo2&”;
 strArr[4]  =   “&te”;
 strArr[5]  =   “tInfo3”;
 
 


3、根据字符串拆分字符串

 strArr = str.split(new string[]{“&*&”});
 strArr[0] = “testInfo1”;
 strArr[1] = “testInfo2”;
 strArr[2] = “testInfo3”;


4、根据多个字符串拆分字符串

 strArr = str.split(new string[]{“&*&”,”es”});
 strArr[0] = “t”;
 strArr[1] = “tInfo1”;

 strArr[2] = “t”;
 strArr[3] = “tInfo2”;

 strArr[4] = “t”;
 strArr[5] = “tInfo3”;