62,046
社区成员
发帖
与我相关
我的任务
分享
string str = "kc0001,kc0002,kc00003,kc0004";
string[] strs = str.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries);
foreach (string s in strs)
{
//插入
}
var arr=str.split(",");
for( var a in arr)
{
alert(a);
}
public static List<string> Split(string postTag)
{
Regex re = new Regex("\"[\\s\\S]*?\"");
MatchCollection mas = re.Matches(postTag);
List<string> list = new List<string>();
string TemPost = re.Replace(postTag, ",^#^,");
string[] splitstr = { " ", ",", "、", ",", "=", "$" };
string[] temarray = TemPost.Split(splitstr, StringSplitOptions.RemoveEmptyEntries);
int j = 0;
for (int i = 0; i < temarray.Length; i++)
{
if (!string.IsNullOrEmpty(temarray[i]))
{
if (temarray[i] == "^#^")
{
temarray[i] = mas[j].Value;
j++;
}
list.Add(temarray[i]);
}
}
return list;
}
///pSplitstr是你传入的自定义分隔符”比如逗号啦,句号啦“
public static List<string> Split(string postTag, string[] pSplitstr)
{
Regex re = new Regex("\"[\\s\\S]*?\"");
MatchCollection mas = re.Matches(postTag);
List<string> list = new List<string>();
string TemPost = re.Replace(postTag, ",^#^,");
//string[] splitstr = { " ", ",", "、", ",", "=", "$" };
string[] temarray = TemPost.Split(pSplitstr, StringSplitOptions.RemoveEmptyEntries);
int j = 0;
for (int i = 0; i < temarray.Length; i++)
{
if (!string.IsNullOrEmpty(temarray[i]))
{
if (temarray[i] == "^#^")
{
temarray[i] = mas[j].Value;
j++;
}
list.Add(temarray[i]);
}
}
return list;
}
var arr=str.split(",");
foreach( var a in arr)
{
alert(a);
}