Skip to content
Advertisement

Extraction of string and integer from txt

I’m trying to make a simple scanner reader to read from a txt stored in C:UsersjamesDesktopprojectfiles and it’s called data “data.txt”, the thing is that the information stored is like this:

JavaScript

So as you can see the spaces between the string and the integer that I want o extract are random. I was trying to make this:

JavaScript

But the split is only with one empty space between the string and the integer so I would like to know how can I extract that two things that are separated with any number of spaces in the same line. Example:

JavaScript

Advertisement

Answer

Instead of data.split(" ")

you can use

JavaScript

Also your function won’t compile because it does not have any return.

Advertisement