Question Get user input into array

jojo159

New member
Joined
May 17, 2011
Messages
2
Programming Experience
Beginner
In my program, I need to have the user input a list of numbers separated by commas. How would I go about storing those numbers? Would I put them into an array? If so, how?
I'm REALLY new at this and I have been all over Google but I can't seem to get it. Please Help!
 
If I understand you right, you need to use the String.Split() method:

Dim strInfo As String = "Item1,Item2,Item3,Item3"
Dim strInfoArray() As String = strInfo.Split(",")

'Another option is to just create an array without using the Split() method:

Dim strInfoArray() As String = {"Item1", "Item2", "Item3", "Item4"}


You might also look into using lists, that way you can use the Add() function:

Dim lstInfo As New List

'Adding items
lstInfo.Add("Item1")

'Converting list to a string array
Dim strInfoArray() As String = lstInfo.ToArray()


Hope this helps
-Josh
 
Glad to help!
 
Its always recommended to use the generic version of a list.

VB.NET:
Dim numbers As New List(Of Integer)
this prevents unboxing.
 
Right, sorry about that. I was just typing from memory :).

Dim lstInfo As New List(Of String)
 
Back
Top