Split into special characters like '\' in java [duplicate]

1

Hello, I would like to know how I make a split to special characters. What I'm trying to do is take away the \ these numbers.

String octa = "454246";
   String[] prueba = octa.split("\");
    for (int i = 0; i < prueba.length; i++) {


    System.out.println(":"+Long.toHexString(Long.parseLong(prueba[i],8)));
     }
    
asked by Brayan Espinoza 08.01.2018 в 22:25
source

1 answer

2

You must perform an escape of the character \ an option is:

 String[] prueba = octa.split("\\");

Another option is to use the Pattern class:

    String octa = "454246";
    String separator = "\";
    String[] prueba = octa.split(Pattern.quote(separator));
    
answered by 08.01.2018 в 22:28