Filipe Costa Filipe Costa - 2 months ago 27
Vb.net Question

Split integer into array VB

Good afternoon,

How can i split a value and insert it into a array in VB?

An example:

The initial value is 987654321.

Using a for loop i need to insert the value as something like this:

Position(1) = 9 'The first number from the splited integer

Position(2) = 8 'The second number from the splited integer

and so on...

Thank you.

Answer

This code is untested:

Dim x As Integer = 987654321
Dim s As String = x.ToString
Dim a(s.Length) As String

For i As Integer = 0 To s.Length - 1
  a(i) = s.Substring(i, 1)
Next i
Comments