views:

47

answers:

1

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?

+5  A: 

.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)
Matthew Flaschen
been there done that myself ;-)
BrokenGlass
Yup silly me...I actually looked at the API but interpreted it wrong.
Marquinio