10-26-2013, 07:31 AM
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
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