我看了一段代码,不知道为什么要用if (strLength > 4) strFilter = strTempFilter.Remove(strLength-5,4);

giantboy520 2005-11-14 09:07:23
如题:为什么要用这个呢?到底删去了里面什么呢?
if (strLength > 4)
strFilter = strTempFilter.Remove(strLength-5,4);

-----------------------------------------------------------------------------------
1:
string strFilter = "";
string strTempFilter = "";
if (this.txt_mingcheng.Text.Trim() != "")
strTempFilter += "mingcheng like '" + this.txt_mingcheng.Text.Trim() + "%' and ";
if (this.txt_changshang.Text.Trim() != "")
strTempFilter += "changshang like '" + this.txt_changshang.Text.Trim() + "%' and ";
int strLength = strTempFilter.Length;
if (strLength > 4)
strFilter = strTempFilter.Remove(strLength-5,4);
ViewState["strFilter"] = strFilter;
BindDataGrid();

---------------------------------------------------------------------------------------
2:
string strFilter="";
string strTempFilter="";
if(this.txt_mingcheng.Text.Trim()!=null)
strTempFilter+=" mingcheng like '"+txt_mingcheng.Text.Trim()+"%'and";
if(this.txt_Danwei.Text.Trim()!=null)
strTempFilter+=" danwei like '"+txt_Danwei.Text.Trim()+"%'and";
if(this.list_blPay.SelectedIndex==0)
{}
else if(this.list_blPay.SelectedIndex==1)
strTempFilter+=" fukuanfou = ' 未知 ' and ";
else if(this.list_blPay.SelectedIndex==2)
strTempFilter+=" fukuanfou = '是'and";
else if(this.list_blPay.SelectedIndex==3)
strTempFilter+=" fukuanfou = ' 否 ' and ";
if(this.DropDownList2.SelectedIndex!=0)
strTempFilter+="riqi='"+DropDownList2.SelectedIndex.ToString().Trim()+"%'and";
int strLength=strTempFilter.Length;
if(strLength>4)
strFilter=strTempFilter.Remove(strLength-5,4);
ViewState["strFilter"]=strFilter;
BindDataGrid();
...全文
86 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
giantboy520 2005-11-14
  • 打赏
  • 举报
回复
我也觉得奇怪!是利用把条件筛选到DataView中的RowFilter来显示查询的!
charles_y 2005-11-14
  • 打赏
  • 举报
回复
不过感觉这种删除方法比较奇怪.......
charles_y 2005-11-14
  • 打赏
  • 举报
回复
不好意思,错了。
应该是如果字符串的长度超过4个,则删除掉后面4个字符,前面保留的字符数不定
cjzlxy 2005-11-14
  • 打赏
  • 举报
回复
楼上正解
如果字符串的长度超过4个,只取前四个.
giantboy520 2005-11-14
  • 打赏
  • 举报
回复
应该不对!
charles_y 2005-11-14
  • 打赏
  • 举报
回复
应该是如果字符串的长度超过4个,则保留前4个字符,后面的删除掉

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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