「Java」エスケープシーケンスのサンプル
環境
JavaSe-17
Spring Tool Suite 4.13
利用可能なエスケープシーケンス一覧
¥b バックスペース
¥t タブ文字
¥n ラインフィールド(改行)
¥r キャリッジリターン(復帰)
¥f フォームフィード(改ページ)
¥' シングルクォーテーション
¥"" ダブルクォーテーション
¥¥ エン文字
¥b バックスペース
¥t タブ文字
¥n ラインフィールド(改行)
¥r キャリッジリターン(復帰)
¥f フォームフィード(改ページ)
¥' シングルクォーテーション
¥"" ダブルクォーテーション
¥¥ エン文字
¥b バックスペース ¥t タブ文字 ¥n ラインフィールド(改行) ¥r キャリッジリターン(復帰) ¥f フォームフィード(改ページ) ¥' シングルクォーテーション ¥"" ダブルクォーテーション ¥¥ エン文字
使用例
package com.arkgame.study;
public class Test {
public static void main(String[] args) {
// タブ文字
String resA = "study\ttest";
// 復帰
String resB = "study\r\ntest";
// 改行
String resC = "study\ntest";
// シングルクォーテーション
String resD = "study\'test";
// ダブルクォーテーション
String resE = "study\"test";
// 円文字
String resF = "study\\test";
System.out.println("タブ文字のエスケープ:\n" + resA);
System.out.println("キャリッジリターン(復帰)のエスケープ:\n" + resB);
System.out.println("ラインフィールド(改行)のエスケープ:\n" + resC);
System.out.println("シングルクォーテーションのエスケープ:\n" + resD);
System.out.println("ダブルクォーテーションのエスケープ:\n" + resE);
System.out.println("エン文字のエスケープ:\n" + resF);
}
}
package com.arkgame.study;
public class Test {
public static void main(String[] args) {
// タブ文字
String resA = "study\ttest";
// 復帰
String resB = "study\r\ntest";
// 改行
String resC = "study\ntest";
// シングルクォーテーション
String resD = "study\'test";
// ダブルクォーテーション
String resE = "study\"test";
// 円文字
String resF = "study\\test";
System.out.println("タブ文字のエスケープ:\n" + resA);
System.out.println("キャリッジリターン(復帰)のエスケープ:\n" + resB);
System.out.println("ラインフィールド(改行)のエスケープ:\n" + resC);
System.out.println("シングルクォーテーションのエスケープ:\n" + resD);
System.out.println("ダブルクォーテーションのエスケープ:\n" + resE);
System.out.println("エン文字のエスケープ:\n" + resF);
}
}
package com.arkgame.study; public class Test { public static void main(String[] args) { // タブ文字 String resA = "study\ttest"; // 復帰 String resB = "study\r\ntest"; // 改行 String resC = "study\ntest"; // シングルクォーテーション String resD = "study\'test"; // ダブルクォーテーション String resE = "study\"test"; // 円文字 String resF = "study\\test"; System.out.println("タブ文字のエスケープ:\n" + resA); System.out.println("キャリッジリターン(復帰)のエスケープ:\n" + resB); System.out.println("ラインフィールド(改行)のエスケープ:\n" + resC); System.out.println("シングルクォーテーションのエスケープ:\n" + resD); System.out.println("ダブルクォーテーションのエスケープ:\n" + resE); System.out.println("エン文字のエスケープ:\n" + resF); } }
実行結果
タブ文字のエスケープ:
study test
キャリッジリターン(復帰)のエスケープ:
study
test
ラインフィールド(改行)のエスケープ:
study
test
シングルクォーテーションのエスケープ:
study'test
ダブルクォーテーションのエスケープ:
study"test
エン文字のエスケープ:
study\test
タブ文字のエスケープ:
study test
キャリッジリターン(復帰)のエスケープ:
study
test
ラインフィールド(改行)のエスケープ:
study
test
シングルクォーテーションのエスケープ:
study'test
ダブルクォーテーションのエスケープ:
study"test
エン文字のエスケープ:
study\test
タブ文字のエスケープ: study test キャリッジリターン(復帰)のエスケープ: study test ラインフィールド(改行)のエスケープ: study test シングルクォーテーションのエスケープ: study'test ダブルクォーテーションのエスケープ: study"test エン文字のエスケープ: study\test