Check if string contains \n Java

前端 未结 4 469
别那么骄傲
别那么骄傲 2020-12-10 01:18

How do I check if string contains \\n or new line character ?

word.contains(\"\\\\n\")
word.contains(\"\\n\")
4条回答
  •  无人及你
    2020-12-10 02:06

    For portability, you really should do something like this:

    public static final String NEW_LINE = System.getProperty("line.separator")
    .
    .
    .
    word.contains(NEW_LINE);
    

    unless you're absolutely certain that "\n" is what you want.

提交回复
热议问题