-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
  • 5,985
  • 1
  • 26
  • 50
trustidkid
  • 507
  • 4
  • 5

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
  • 5,603
  • 4
  • 25
  • 45