Backslash in java

前端 未结 4 1165
北海茫月
北海茫月 2021-01-21 13:57

I have a problem with strings saved in a database, like this for example: \"311\\315_316\\336_337\". They have only one backslash and this is a problem in java. Wh

4条回答
  •  孤街浪徒
    2021-01-21 14:57

    The data in the database is OK, and you don't have to replace anything. String literals, written directly in the Java code, must have their backslash escaped by another backslash:

    String s = "311\\315_316\\336_337";
    System.out.println(s); // prints 311\315_316\336_337
    

    But if you get those values from the database, you don't have anything to do:

    String s = resultSet.getString(1);
    System.out.println(s); // should print 311\315_316\336_337
    

提交回复
热议问题