Reputation: 4831
I'm getting an ArgumentOutOfRange error when using substring function in .NET. I'm new to .NET so probably doing something wrong. I have a txtField, which is a text field component in GUI. I'm using Microsoft Visual Basic 2010 Express
txtField.Substring(txtField.Length-4,txtField.Length-1)
If txt.Field contains only numberic values it works ok, but as soon as the text field contains characters it breaks.
Anyone have any ideas?
Upvotes: 0
Views: 1071
Reputation: 285077
.NET takes the length of the substring as the second parameter, not the end (exclusive). So if you want three characters, do:
txtField.Substring(txtField.Length-4, 3)
Upvotes: 5