Kedar Karki
Kedar Karki

Reputation: 538

How to take stdin input and break in whitespace in dart?

I want to take 5 inputs like

1 2 3 4 5

using a for loop that runs 5 times.

stdin.readLineSync() takes the whitespace as an input and continues until I press ENTER but I want it to separate by whitespace like scanf in C.

How can I do that ?

Upvotes: 0

Views: 434

Answers (1)

jamesdlin
jamesdlin

Reputation: 89946

After you read a line with readLineSync(), you can split it by whitespace with String.split and then iterate over the tokens:

var line = stdin.readLineSync();
var tokens = line.split(RegExp(r'\s+'));

Upvotes: 1

Related Questions