「Java」ダブルコーテーション(シングルコレクション)で文字列を囲んで出力するサンプル

説明
シングルクォーテーション \’
ダブルコーテーション \"
Javaコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study.st2;
public class StringKakomiDemo {
protected static final String strM = "\"";
protected static final String strK = "\'";
public static void main(String[] args) {
String strA = "arkgame.com";
String strB = "T";
mojiReFunc(strA, strM);
mojiReFunc(strB, strK);
}
public static void mojiReFunc(String target, String pattern) {
String res;
System.out.println("対象文字:" + target);
res = pattern + target + pattern;
System.out.println("囲い文字を出力結果:" + res);
}
}
package com.arkgame.study.st2; public class StringKakomiDemo { protected static final String strM = "\""; protected static final String strK = "\'"; public static void main(String[] args) { String strA = "arkgame.com"; String strB = "T"; mojiReFunc(strA, strM); mojiReFunc(strB, strK); } public static void mojiReFunc(String target, String pattern) { String res; System.out.println("対象文字:" + target); res = pattern + target + pattern; System.out.println("囲い文字を出力結果:" + res); } }
package com.arkgame.study.st2;

public class StringKakomiDemo {

      protected static final String strM = "\"";
      protected static final String strK = "\'";

      public static void main(String[] args) {
            String strA = "arkgame.com";
            String strB = "T";
            mojiReFunc(strA, strM);
            mojiReFunc(strB, strK);
      }

      public static void mojiReFunc(String target, String pattern) {
            String res;
            System.out.println("対象文字:" + target);
            res = pattern + target + pattern;
            System.out.println("囲い文字を出力結果:" + res);
      }
}

実行結果
対象文字:arkgame.com
囲い文字を出力結果:"arkgame.com"
対象文字:T
囲い文字を出力結果:’T’

Java

Posted by arkgame