Alex Rivera | Logout

Split string by char in java

Asked 2011-03-14T08:49:37.657
14

I'm getting a string from the web looking like this:

Latest Episode@04x22^Killing Your Number^May/15/2009

Then I need to store 04x22, Killing Your Number and May/15/2009 in diffent variables, but it won't work.

String[] all = inputLine.split("@");
String[] need = all[1].split("^");
show.setNextNr(need[0]);
show.setNextTitle(need[1]);
show.setNextDate(need[2]);

Now it only stores NextNr, with the whole string

04x22^Killing Your Number^May/15/2009

What is wrong?

Edit
Report

1 Answer

23

If you have a separator but you don't know if it contains special characters you can use the following approach

String[] parts = Pattern.compile(separator, Pattern.LITERAL).split(text);
answered 2011-03-14T09:10:43.970

Your Answer