Is there a function in VB.net that allows me to divide a really long String into a specific number of characters?

For example:

MyString= "Hello man! Wazzup?"

group1="Hello "
group2="man! W"
group3="azzup?"

The length of this string is 18 and I'd like to group it by 3, so each group would contain 6 characters. Is there an easier way of doing this? Is there a predefined function in VB.net? I'm already thinking of doing it manually, like converting the string into characters and storing them inside arrays. *My plan is still a bit fuzzy :P* But yeah, if you know of an easier way, then please let me know. :) thanks.

I do not know any function to split by size, but you can implement your own thing like:

' Define the string to be split by length
	Dim MyString As String = "Hello man! Wazzup?"
' Call your defined split string by size function
	Dim MyGroups() As String = SplitStringBySize(MyString, 3)
.
.
.
'
' Function defined
'
Function SplitStringBySize(ByVal StringToSplit as String, ByVal NumberOfGroups as Integer) as String()
' Validate the Input
If NumberOfGroups > 1 AndAlso MyString.Length > 0 Then
' Define the groups to receive the splittet parts
	Dim Group(NumberOfGroups - 1) As String
' Define the length of each part
	Dim GroupLength As Integer = StringToSplit.Length \ NumberOfGroups
' Split the String
	For I As Integer = 0 To NumberOfGroups - 1
		Group(I) = StringToSplit.Substring(I * GroupLength, GroupLength)
	Next
	Return Group
Else
	Return Nothing
End If
End Function

Hope this helps

This article has been dead for over six months. Start a new discussion instead.