「Java」特殊文字のエスケープシーケンスを使うサンプル
書式
シングルクォーテーション \’
ダブルクォーテーション \"
円文字 \\
使用例
package com.arkgame.info;
public class EscapeDemo {
public static void main(String[] args) {
// シングルクォーテーション
String strA = "study \'skill\'in \'arkgame\'";
// ダブルクォーテーション
String strB = "become \" smart \"in \"arkgame\"";
// 円文字
String strC = "power \\ is \\ in \\arkgame\\";
// バックスペース
String strD = "test\tdata\t123\tarkgame\t";
escapeFunc(strA);
escapeFunc(strB);
escapeFunc(strC);
escapeFunc(strD);
}
private static void escapeFunc(String target) {
System.out.println(target);
}
}
package com.arkgame.info;
public class EscapeDemo {
public static void main(String[] args) {
// シングルクォーテーション
String strA = "study \'skill\'in \'arkgame\'";
// ダブルクォーテーション
String strB = "become \" smart \"in \"arkgame\"";
// 円文字
String strC = "power \\ is \\ in \\arkgame\\";
// バックスペース
String strD = "test\tdata\t123\tarkgame\t";
escapeFunc(strA);
escapeFunc(strB);
escapeFunc(strC);
escapeFunc(strD);
}
private static void escapeFunc(String target) {
System.out.println(target);
}
}
package com.arkgame.info; public class EscapeDemo { public static void main(String[] args) { // シングルクォーテーション String strA = "study \'skill\'in \'arkgame\'"; // ダブルクォーテーション String strB = "become \" smart \"in \"arkgame\""; // 円文字 String strC = "power \\ is \\ in \\arkgame\\"; // バックスペース String strD = "test\tdata\t123\tarkgame\t"; escapeFunc(strA); escapeFunc(strB); escapeFunc(strC); escapeFunc(strD); } private static void escapeFunc(String target) { System.out.println(target); } }
実行結果
study 'skill’in 'arkgame’
become " smart “in “arkgame"
power \ is \ in \arkgame\
test data 123 arkgame