Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with dividing a string
#4
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!
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Problems with dividing a string - by brco900033 - 10-19-2013, 12:09 PM
Re: Problems with dividing a string - by brandonio21_phpbb3_import2 - 10-23-2013, 02:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search ListBox + Convert ListBox.item to string brco900033 3 14,577 09-13-2012, 03:03 PM
Last Post: brandonio21
  How to write string query on multiple lines kismetgerald 1 8,960 08-29-2012, 04:01 PM
Last Post: brandonio21
  VB.Net Query Builder Problems. Moldraxian 2 12,537 08-17-2012, 05:33 AM
Last Post: Moldraxian
  Outputting a string with quotation marks in it. openeXpressions 15 47,650 12-20-2011, 09:24 PM
Last Post: openeXpressions
  Problems with multiple textboxes and coding LearningVB2010 30 92,829 02-28-2011, 07:39 AM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)