如何在asp.net中修剪字符串 [英] how to trim string in asp.net

查看:103
本文介绍了如何在asp.net中修剪字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net中修剪字符串...
我的问题是这个...

str2 = str2 + "," + CheckBoxList2.Items[i].Text;


如果我选择了chekbox的5个项目,则在最后一个项目之后添加,但我不希望这样做,则在字符串的最后插入int. />

 如果(str2 .Length >   1 );
} 


以这种形式使用它希望可以让您清楚明白

 如果((i +  1 )== CheckBoxList2.Items.Count )
          str2 + = CheckBoxList2.Items [i] .Text;
      其他
          str2 + = CheckBoxList2.Items [i] .Text + " ; 


计算List的长度并应用if条件,如果变量小于长度,则应用,",否则,如果其等于长度,则跳过,"

how to trim string in asp.net...
my Problem is this...

str2 = str2 + "," + CheckBoxList2.Items[i].Text;


if i am selected 5 item of chekbox then after last item , is added but i dont want that , is inculed in last of string

解决方案

try this its simple

if (str2 .Length > 0)
{
str2 = str2 .Remove(str2 .Length - 1);
}


Use it in this form hope makes it clear to you

if ((i + 1) == CheckBoxList2.Items.Count)
          str2 +=  CheckBoxList2.Items[i].Text;
      else
          str2 += CheckBoxList2.Items[i].Text + ", ";


Calculate the length of the List and apply the if condition, if the variable is less than the length then apply "," else if its equal to the length then skip the ","


这篇关于如何在asp.net中修剪字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆