Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Updated 11-May-22 2:49am

int backSlashIndex = text.IndexOf("\\");
domain = (backSlashIndex >= 0) ? text.Substring(0, backSlashIndex) : text;
 
Share this answer
 
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.
 
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