Jelte Knossen
Jelte Knossen

Reputation: 11

How do i put only the first string of a line in an array while using console.readline

I need to only get the first Numbers of an input line from the console. If the console gives input being:

20 //this is some input text

Then I need my array to be only filled with the number 20 while still using console.readline.

Upvotes: 1

Views: 59

Answers (1)

Dan
Dan

Reputation: 3713

I'm guessing maybe you're working in C#???

Try this:

var line = "20 //this is some input text";
var num = int.Parse(line.Substring(0, line.IndexOf(' ')));

Then use the variable num for whatever you want. You can put it in an array like you want.

Upvotes: 1

Related Questions