开发者

.net substring not working

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 te开发者_如何学编程xt 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?


.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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜