Java8 バックスラッシュのエスケープシーケンスサンプル
環境
Windows 10 Home 64bit
Java SE 1.8
Eclipse 4.14
書式
\\ バックスラッシュ
文字列.replaceAll(“\\\\", “\\\\\\\\");
replaceAll関数を使ってバックスラッシュをエスケープします。
使用例
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);
}
}
結果
test\\\\123\\\\abc