「Java8」特殊文字パーセント文字列をエスケープする
環境
Java8
Eclipse 4.14.0
書式
public static String format(String format,Object… args)
指定された書式の文字列と引数を使って、書式付き文字列を返します。
使用例
package com.arkgame.info;
public class SekiDemo {
/* %%でパーセント文字列をエスケープ */
private static String ptn = "%%";
public static void main(String[] args) {
String target = "price cost 55";
String strA = String.format("%s", target);
System.out.println("パーセント文字列をエスケープ前: " + strA);
String strB = String.format("%s" + ptn, target);
System.out.println("パーセント文字列エスケープ後: " + strB);
}
}
実行結果
%エスケープ前: price cost 55 %エスケープ後: price cost 55%