-2

I have string am retrieving from API that contains a this character "|". I will like to split the string with "|" I tried several options but failed.

String response="The general String | Yesterday"; 
String splitResponse = response.split("|");
// also tried this 
reponse.split("(?<=|)"); //no success
leonardkraemer
  • 6,573
  • 1
  • 31
  • 54
trustidkid
  • 577
  • 4
  • 6

1 Answers1

0

In order to split using '|' you need to remove the escape character using below.

String response="The general String | Yesterday"; 
    String []splitResponse = response.split("\\|");
    for(int i=0;i<splitResponse.length;i++) {
        System.out.println(splitResponse[i]);
    }

Split method split your string on REGEX.

kj007
  • 6,073
  • 4
  • 29
  • 47