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

Sangram Anand
  • 10,526
  • 23
  • 70
  • 103

4 Answers4

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";
Razvan
  • 9,925
  • 6
  • 38
  • 51
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);
    }
Vinesh
  • 933
  • 2
  • 7
  • 22
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
Averroes
  • 4,168
  • 6
  • 50
  • 63
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]);
    }
Owen
  • 174
  • 1
  • 1
  • 9