kielou kielou -4 years ago 172
Vb.net 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.

Example:
Input
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))

Console.WriteLine(Join(intList))
Console.ReadLine()

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))
Array.Sort(intList)

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