Question

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

Was it helpful?

Solution

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";

OTHER TIPS

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

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]);
    }

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);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top