remove start string and end string from selected text

sputnik75043

Member
Joined
Aug 28, 2010
Messages
13
Programming Experience
Beginner
I'm trying to remove the HTML comment tags from a selected string and I'm getting an error....
Let's say I have a selected string:
<!--This is my string-->

selText is my variable for the entire selected string - my code is:
VB.NET:
selText = selText.Substring(4, selText.Length - 3)

The error is :
Index and length must refer to a location within the string.
Parameter name: length


What's wrong here?
 
Let's say your selText string is this:
<!--This is my string-->
The length of that string is 24. Char indexes is 0-23.
Your expression (selText.Length-3) equals (24-3)=21. That means you are asking for 21 chars starting from index 4.
4+21=25, 25th char would have index 24 and that is not a valid location/index in that string, the highest index is 23.
 
Back
Top