10-23-2013, 02:33 PM
This would be expected when we reach the end of the string since its length is not divisible by 4. For example, there might be 3 characters left, but we are trying to grab the next four. What you can do to prevent this is know exactly when we run out of sequences of 4 characters and subtract the amount we need. For example,
[code2=vbnet]Dim remainder as Integer = s.Length Mod 4
For i = 0 To (s.Length - remainder) Step 4
strings.Add(s.Substring(i, 4))
Next
strings.Add(s.Substring(s.length - remainder, remainder)[/code2]
Essentially, this divides the string by 4 and gets the remainder, which is how many characters are left over when the error is thrown. To prevent the error from being thrown, we only move up to the last slot divisible by 4 in the For loop and then we add on the remaining integers at the end.
Let me know if this works or if you have any questions!
[code2=vbnet]Dim remainder as Integer = s.Length Mod 4
For i = 0 To (s.Length - remainder) Step 4
strings.Add(s.Substring(i, 4))
Next
strings.Add(s.Substring(s.length - remainder, remainder)[/code2]
Essentially, this divides the string by 4 and gets the remainder, which is how many characters are left over when the error is thrown. To prevent the error from being thrown, we only move up to the last slot divisible by 4 in the For loop and then we add on the remaining integers at the end.
Let me know if this works or if you have any questions!