0

I want to split a string between two semicolons (:). i.e.,

BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980

I am trying

split("[\\:||\\:]");

but its not working

1

4 Answers 4

3

Use split with ":" as the regex.

More precisely:

  String splits[] = yourString.split(":");
  //splits will contain: 
  //splits[0] = "BOOLEAN";
  //splits[1] = "Mr. Coffee - Recall";
  //splits[2] = "8a42bb8b36a6b0820136aa5e05dc01b3";
  //splits[3] = "1346790794980";
1
  • Is it possible to split the string from the second occurrence of ":" i.e., get the - BOOLEAN: Mr. Coffee - Recall Sep 18, 2012 at 10:28
0

This:

  String m = "BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980";
  for (String x : m.split(":"))
    System.out.println(x);

returns

BOOLEAN
 Mr. Coffee - Recall
8a42bb8b36a6b0820136aa5e05dc01b3
1346790794980
0

Regex flavoured:

    String yourString = "BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980";
    String [] componentStrings = Pattern.compile(":").split(yourString);

    for(int i=0;i<componentStrings.length;i++)
    {
        System.out.println(i + " - " + componentStrings[i]);
    }
0

You can use split(), Refer this code,

String s ="BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980";

String temp = new String();


    String[] arr = s.split(":");

    for(String x : arr){
      System.out.println(x);
    }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.