StartIndex不能小于零.参数名称:startIndex [英] StartIndex cannot be less than zero. Parameter name: startIndex

查看:1303
本文介绍了StartIndex不能小于零.参数名称:startIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了"StartIndex不能小于零.
当我在aspx代码中使用<%= text.Remove(text.LastIndexOf('',''))%>"时,参数名称:startIndex",因为我认为这是由于值为空. > 紧急帮助plz
谢谢

i got "StartIndex cannot be less than zero.
Parameter name: startIndex" when i use "<%=text.Remove(text.LastIndexOf('',''))%>" in my aspx code .as i think this is due to empty value.
Urgent help plz
Thanks

推荐答案

int backSlashIndex = text.IndexOf("\\");
域=(backSlashIndex> = 0)? text.Substring(0,backSlashIndex):text;
int backSlashIndex = text.IndexOf("\\");
domain = (backSlashIndex >= 0) ? text.Substring(0, backSlashIndex) : text;


您所得到的错误非常明显-对于基于零的索引方案,您不能传递小于零的错误.

而且我认为由于找不到字符串'',''LastIndexOf给出-1

http://msdn.microsoft.com/en-us/library/9ad138yc.aspx [ ^ ]

尝试检查此-1返回值并进行相应处理.
The error you got is pretty clear - You can not pass less than zero for an ZERO-BASED indexing scenarios.

And I think as no string '','' is found LastIndexOf is giving -1

http://msdn.microsoft.com/en-us/library/9ad138yc.aspx[^]

Try checking this -1 return and handle accordingly.


这篇关于StartIndex不能小于零.参数名称:startIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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