在asp.net中启动索引错误 [英] start index error in asp.net

查看:73
本文介绍了在asp.net中启动索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string _fAppContent = System.Text.Encoding.UTF7.GetString(_appBuffer);
_fAppContent = _fAppContent.Substring(_fAppContent.IndexOf(< html>"))
这是我的代码,但出现错误
startindex不能小于零

string _fAppContent = System.Text.Encoding.UTF7.GetString(_appBuffer);
_fAppContent =_fAppContent.Substring(_fAppContent.IndexOf("<html>"))
this is my code and i am getting an error
startindex cannot be less than zero

推荐答案

string.IndexOf如果找不到所需的字符串,则返回-1,因此此调用:

string.IndexOf will return -1 if it can''t find the string you''re looking for, so this call:

_fAppContent.IndexOf("<html>")



返回-1,因为找不到"<html>".检查_appBuffer是否确实包含某些内容,_fAppContent实际上是否包含某些内容,以及传递给IndexOf的搜索字符串是否正确.



Is returning -1 because it can''t find "<html>". Check that _appBuffer actually contains something, that _fAppContent actually contains something and that the search string you pass to IndexOf is in the correct case.


检查Substring之前的if条件如下

Check the if condition before Substring as below

string _fAppContent = System.Text.Encoding.UTF7.GetString(_appBuffer);
if (_fAppContent.IndexOf("<html>") >= 0)
{
   _fAppContent = _fAppContent.Substring(_fAppContent.IndexOf("<html>"));
}



因此,如果找不到匹配的字符串,则Substring不会给您错误.



so that if matching string is not found then Substring would not give you error.


这篇关于在asp.net中启动索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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