在asp.net中启动索引错误 [英] start index error in 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屋!