Java8 バックスラッシュのエスケープシーケンスサンプル

環境
Windows 10 Home 64bit
Java SE 1.8
Eclipse 4.14

書式
\\ バックスラッシュ
文字列.replaceAll(“\\\\", “\\\\\\\\");
replaceAll関数を使ってバックスラッシュをエスケープします。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
public class EscapeExample {
public static void main(String[] args) {
String strA = "test\\\\123\\\\abc";
// バックスラッシュをエスケープする
String res = strA.replaceAll("\\\\", "\\\\\\\\");
System.out.println(res);
}
}
package com.arkgame.study; public class EscapeExample { public static void main(String[] args) { String strA = "test\\\\123\\\\abc"; // バックスラッシュをエスケープする String res = strA.replaceAll("\\\\", "\\\\\\\\"); System.out.println(res); } }
package com.arkgame.study;

public class EscapeExample {

      public static void main(String[] args) {
            String strA = "test\\\\123\\\\abc";
            // バックスラッシュをエスケープする
            String res = strA.replaceAll("\\\\", "\\\\\\\\");
            System.out.println(res);
      }
}

結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
test\\\\123\\\\abc
test\\\\123\\\\abc
test\\\\123\\\\abc

 

Java

Posted by arkgame