一个Session["shop"]是"1,5,32",怎么变成"5,32"
一个Session[ "shop "]= "1,5,32 ",怎么除掉第一项变成 "5,32 "
------解决方案--------------------index 为要去掉的项,以0起始
private string t(string str,int index)
{
string returnstr=string.Empty ;
string[] alist=str.Split( ', ');
for(int i=0;i <alist.Length;i++)
{
if(i!=index)
{
if(i==0)
{
returnstr=alist[i];
}
else if((i==1) && (index==0))
{
returnstr=alist[i];
}
else
{
returnstr=returnstr+ ", "+alist[i];
}
}
}
return returnstr;
}
------解决方案--------------------利用sqlit()把。存至一个数组。然后比较删除。在取出连接!
protected void test()
{
string t = "1,5,6, ";
string[] arr;
arr= t.Split( ', ');
string testString = "5 ";
string outer = " ";
for (int i = 0; i <= arr.Length - 1; i++)
{
if (arr[i] == testString)
arr[i] = " ";
}
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] != " ")
{
outer += arr[i]+ ", ";
}
}
Response.Write(outer);
}