0

I'm try to go through a file that's formatted as follows:
f 5//10 3//2 6//3
f 9//3 20//15 3/20
etc.
I want to pull out the numbers, subtract them by some set number, and then output them. I'm using a scanner to read each line of the file, but next Int doesn't seem to work since I have the // between some of the numbers. I know there has to be some simple way to deal with this, but I'm having a hard time finding what to do.

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by masijade
0

Thanks for the help, but I'm not sure what you mean by 'split'...it doesn't seem to be a method in either BufferedReader or Scanner.


Edit: Ah, I see - split is in String. But when I put the regular expression you provided into split, it says it's invalid. Sorry...I'm not good with regular expressions.

Edited by SiraRaven: n/a

0
String regex = ("[^\\d\\s]");
 String text = "f 5//10 3//2 6//3";
text.split(regex);

edit:
or

String regex = ("[\\s\\\\[^\\d]\\s]");

the above code pull out all the integer..

try yourself to get clear output.

Edited by musthafa.aj: n/a

0

And much more complicated than need be. simply split on one or more whitespace or one or more "/" characters (as I did) and ignore the first index.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.