字符串分割

reddust 2003-08-20 11:05:15
我想将CheckBoxList里选定的ListItem项的文本放到一个字符串数组中,并且每个用|分格。代码如下:
string temp="";
for(int i=0;i<CheckBoxList1.Items.Count;i++)
{
if(CheckBoxList1.Items[i].Selected)
{
temp+=CheckBoxList1.Items[i].Text+"|";

}
}

问题是不管有多少项总是在最后加了个|,我不想要开始和最后有这个|
...全文
59 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yohomonkey 2003-08-21
  • 打赏
  • 举报
回复
if(CheckBoxList1.Items[i].Selected)
{
if(temp=="")
{
temp=CheckBoxList1.Items[i].Text;
}
else if (temp<>"")
{
temp= temp + "|" + CheckBoxList1.Items[i].Text;
}

}
angelior 2003-08-21
  • 打赏
  • 举报
回复
if(CheckBoxList1.Items[i].Selected)
{
if(temp=="")
{
temp=CheckBoxList1.Items[i].Text;
}
{
temp= temp + "|" + CheckBoxList1.Items[i].Text;
}

}
reddust 2003-08-21
  • 打赏
  • 举报
回复
好的,结账!!!
kuki84 2003-08-21
  • 打赏
  • 举报
回复
temp = temp.Substring(0,temp.Length - 1);
cnhgj 2003-08-20
  • 打赏
  • 举报
回复
temp = temp.Substring(0,temp.Length - 1);
saucer 2003-08-20
  • 打赏
  • 举报
回复

if (temp != "")
temp = temp.Substring(0,temp.Length - 1);

or

if (temp != "")
temp = temp.TrimEnd('|');



110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧