Reputation: 1281
I'm new to Scala and unsure of how to achieve the following
I have the String
val output = "6055039\n3000457596\n3000456748\n180013\n"
I want to extract the numbers separated by \n and store them in an Array
Upvotes: 0
Views: 178
Reputation: 381
output.split("\n").map(_.toInt)
Or only
output.split("\n")
if you want to keep the numbers in String format. Note that .toInt
throws. You might want to wrap it accordingly.
Upvotes: 1