Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with dividing a string
#7
Thanks for the help! It works perfectly now!

The final code is below, the function divides the string after the amount of characters you want and with the delimiter you want:

[code2=vbnet]Public Function DivideString(ByVal strKey As String, ByVal intPartLength As Integer, ByVal strDivider As String) As String
Dim keyParts As New List(Of String)
Dim remainder As Integer = strKey.Length Mod intPartLength
For i = 0 To (strKey.Length - remainder - 1) Step intPartLength
keyParts.Add(strKey.Substring(i, intPartLength))
Next
keyParts.Add(strKey.Substring(strKey.Length - remainder, remainder))
Dim strDividedString As String = String.Empty
For Each strPart As String In keyParts
strDividedString = strDividedString & strPart & strDivider
Next
If strDividedString.EndsWith(strDivider) Then Return strDividedString.Trim(CChar(strDivider)) Else Return strDividedString
End Function[/code2]

Thanks again,
Brecht


Messages In This Thread
Problems with dividing a string - by brco900033 - 10-19-2013, 12:09 PM
Re: Problems with dividing a string - by brco900033 - 10-26-2013, 07:31 AM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)