Why don't this substring work where peice of text should stop at first full stop?

Joined
Oct 19, 2010
Messages
5
Programming Experience
Beginner
My code:

Protected Sub SearchView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

If e.Row.RowType = DataControlRowType.DataRow Then

e.Row.Cells(3).Text = e.Row.Cells(3).Text.Substring(0, e.Row.Cells(3).Text.IndexOf("."))

End If

I keep getting error message: Length cannot be less than zero, Parameter name: length
 
You can;t pass a value less than zero as the second argument to Substring. You're using the result of IndexOf as the length and IndexOf will return -1, wich is less than zero, if the specified substring isn't found.
 
Back
Top