kielou kielou -4 years ago 172 Question

How to convert array of string to array of integer

I'm trying to learn VB.

I want to convert the array of string to array of int then sort the new array of in and display it in one line.

2 4 1 2 5

Result: 1 2 2 4 5

I tried some solutions but didn't work

Here is my current code:

Dim stringnum As String = "4 2 3"
Dim result() As String = Split(stringnum, " ")

Dim intList() As Integer

intList = result.ConvertAll(Function(s) Integer.Parse(s))


Answer Source

Try the following

Console.WriteLine("Input your numbers :")

Dim stringnum = Console.ReadLine()
Dim result = Split(stringnum, " ")

Dim intList = Array.ConvertAll(result, Function(str) Integer.Parse(str))

Console.WriteLine(String.Join(" ", intList))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download