Alex Rivera | Logout

Splitting strings based on a delimiter

Asked 2011-12-17T21:09:40.457
9

I am trying to break apart a very simple collection of strings that come in the forms of

0|0
10|15
30|55

etc etc. Essentially numbers that are seperated by pipes.

When I use java's string split function with .split("|"). I get somewhat unpredictable results. white space in the first slot, sometimes the number itself isn't where I thought it should be.

Can anybody please help and give me advice on how I can use a reg exp to keep ONLY the integers?

I was asked to give the code trying to do the actual split. So allow me to do that in hopes to clarify further my problem :)

String temp = "0|0";
String splitString = temp.split("|");

results

\n
0
| 
0

I am trying to get

0
0

only. Forever grateful for any help ahead of time :)

Edit
Report

1 Answer

0

This should work for you:

([0-9]+)
answered 2011-12-17T21:14:28.807

Your Answer