Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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

C#
_fAppContent.IndexOf("<html>")


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.
 
Share this answer
 
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>"));
}


so that if matching string is not found then Substring would not give you error.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900