1

Hello everybody I have this string:

[JOLLY BLU at STAY SHIP,  Voy: 0275/11]

How I can turn this string in a String[]

value[0] = "JOLLY BLU at STAY SHIP";
value[1] = "Voy: 0275/11";

Thankyou much

3
  • why is this tagged as "android"? Commented Jan 16, 2012 at 21:08
  • @savinos Because Android uses Java as a programming language. Commented Jan 16, 2012 at 21:10
  • 1
    yes, I mean this is not specific to android in any way Commented Jan 16, 2012 at 21:13

2 Answers 2

7
str = str.substring(1, str.length() - 1); // cut [ and ] off
String[] parts = str.split(",");
Sign up to request clarification or add additional context in comments.

1 Comment

there's a typo, separator is "," and not ";"
4
String s = "[JOLLY BLU at STAY SHIP,  Voy: 0275/11]";
String temp = s.replace("[", "").replace("]", "");
// or String temp = s.substring(1, s.length() - 1);
String[] sArray = temp.split(",");
sArray[1] = sArray[1].trim(); // remove the whitespaces around the string

1 Comment

third line should probably be temp.split

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.