How To Split A String Into A Fixed Length String Array?
I have a long string like this
dim LongString as String = "123abc456def789ghi"
And I want to split it into a string array. Each element of the array should be in 3 characters length
Dim LongArray(5) As String LongArray(0) = "123" LongArray(1) = "abc" LongArray(2) = "456" LongArray(3) = "def" LongArray(4) = "789" LongArray(5) = "ghi"
How do I split it using VB.net code?
This could work.
Module Module1 Sub Main() Dim LongString As String = "123abc456def789ghi" Dim longlist As New List(Of String) For i As Integer = 0 To Convert.ToInt32(LongString.Length / 3) - 1 longlist.Add(LongString.Substring(i * 3, 3)) Next For Each s As String In longlist Console.WriteLine(s) Next Console.ReadLine() End Sub End Module
And this should work in .Net 1.1
Module Module1 Sub Main() Dim LongString As String = "123abc456def789ghi" Dim longlist(Convert.ToInt32(LongString.Length / 3) - 1) As String For i As Integer = 0 To Convert.ToInt32(LongString.Length / 3) - 1 longlist(i) = (LongString.Substring(i * 3, 3)) Next For i As Integer = 0 To Convert.ToInt32(LongString.Length / 3) - 1 Console.WriteLine(longlist(i)) Next Console.ReadLine() End Sub End Module
- → Function Undefined in Axios promise
- → React formatting dates with momentjs server side
- → Using ReactJs, How do I update my form fields when my parent object sent in from props changes?
- → Visual Studio 2012 Express: Browser returning 500 status trying to download jsx file
- → AngularJS directive: "templateUrl" doesn't work while "template" works
- → how to add cannonical tag for ASPX .NET page
- → Selecting an element by its attribute when it has a colon in its name
- → Function works for NON dynamically loaded images
- → URL routing requires /Home/Page?page=1 instead of /Home/Page/1
- → There are "gaps" between rows in my masonry cards
- → creating sef links and changing plus sign (+) with dash (-)