有没有更好的解决方案?
string str = "'1','2','3','4'";
string[] aa = str.Split(',');
List<string> lststr = new List<string>();
foreach (string bb in aa)
{
string[] cc=bb.Split('\'');
lststr.Add(cc[1]);
}
foreach (string resultstr in lststr)
{
Response.Write(resultstr);
}
------解决方案--------------------呆会会有人教你用正则的
------解决方案--------------------string str = "'1','2','3','4'";
string[] aa = str.Split(',');
List<string> lststr = new List<string>();
foreach (string bb in aa)
{
lststr.Add(bb.ToString());
//这个地方类型转换一下不行吗? 我没测试 应该是可以的
}
foreach (string resultstr in lststr)
{
Response.Write(resultstr);
}
------解决方案--------------------
C# code
string str = "'1','2','3','4'";
string[] _list = Regex.Matches(str,@"(?<=['‘])[^'’,,]+?(?=['‘])").Cast<Match>().Select(a=>a.Value).ToArray();
/*
* [0] "1" string
[1] "2" string
[2] "3" string
[3] "4" string
*/