How to add backslash in string in java

I want to add a "\" character for each line in the list of lines ... I am doing something like this, but instead adds 2 backslashes.

feedbackMsgs.add(behaviorName+"\\"+fbCode);

Result

looks like this: "abc\\def"

how to make sure one backslash is added?

+6
source share
3 answers

It looks like your behaviourName ends with \ or fbCode starts with one.

+8
source

I just ran the program with the following -

 String s = "test" + "\\" + "test2"; System.out.println(s); 

And he prints the following:

 test\test2 

Are you sure there are no variables in the behaviourName or fbCode variables?

+19
source

Try to write / print the behaviorName fbCode and find it yourself!

 System.out.println(behaviorName); System.out.println(fbCode); 
0
source

Source: https://habr.com/ru/post/891006/


All Articles