l3_08 l3_08 - 3 months ago 16
Vb.net Question

Split a string into 2 different substrings vb.net

I'm trying to split a string into 2 subs. The first contains the first 236 (0 to 235) chars and the second one from 237 to the end of the string.

firststr = str.Substring(0, 235)
secondstr = str.Substring(235, strLength) 'strLength is the total length of the string


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

Any help?

Answer

You need something like this:

secondstr = str.Substring(235, strLength - 235)

Because strLength is the length of the entire string, and you're starting at position 235, you're going past the end of the string.