|
シングルクォーテーション、ダブルクォーテーションは、各プログラム言語で意味が異なります。 |
|
|
Perlでは、ダブルクォーテーション、シングルクォーテーションとも文字列を表します。 ただし、クォーテーション内に変数やエスケープシーケンスを記述した際において処理が異なります。 ダブルクォーテーション内に変数を記入した場合は展開されます。 またエスケープシーケンスも有効になります。
$str1 = "big";
$str2 = "small"; print "This is a $str1 dog.\n"; print "That is a $str2 cat.\n";
This is a big dog.
That is a small cat. シングルクォーテーション内に変数を記入した場合は展開されず、そのまま変数名が出力されます。 またエスケープシーケンスも無効になり、そのままの文字列として出力されます。
$str1 = "big";
$str2 = "small"; print 'This is a $str1 dog.\n'; print 'That is a $str2 cat.\n';
This is a $str1 dog.\nThat
is a $str2 cat.\n
ダブルクォーテーション内に変数を記入する際、変数の直後にスペースを入れず、文字を記入しようとすると、どこからどこまでが変数名かPerl実行エンジンが判断できません。そのような場合は、次のように変数名を「{ }」で囲みます。
$num = 200;
print "ファイルサイズを${num}KB以下にしてください。";
ファイルサイズを200KB以下にしてください。
|
|
|
PHPでは、ダブルクォーテーション、シングルクォーテーションとも文字列を表します。 ただし、クォーテーション内に変数やエスケープ文字列を記述した際において処理が異なります。 ダブルクォーテーション内に変数を記入した場合は展開されます。 またエスケープシーケンスも有効になります。
<?php
$str1 = "big"; $str2 = "small"; echo "This is a $str1 dog.\n"; echo "That is a $str2 cat.\n"; ?>
This is a big dog.
That is a small cat. シングルクォーテーション内に変数を記入した場合は展開されず、そのまま変数名が出力されます。 またエスケープシーケンスも無効になり、そのままの文字列として出力されます。
<?php
$str1 = "big"; $str2 = "small"; echo 'This is a $str1 dog.\n'; echo 'That is a $str2 cat.\n'; ?>
This is a $str1 dog.\nThat
is a small cat.\n
ダブルクォーテーション内に変数を記入する際、変数の直後にスペースを入れず、文字を記入しようとすると、どこからどこまでが変数名かPHP実行エンジンが判断できません。そのような場合は、次のように変数名を「{ }」で囲みます。
<?php
$num = 200; echo "ファイルサイズを{$num}KB以下にしてください。\n"; ?>
ファイルサイズを200KB以下にしてください。
|
|
|
Javaでは、ダブルクォーテーションは文字列(String型)、シングルクォーテーションは文字(char型)になります。
public class BasicQuotation
{
public static void main(String[] args) { String str1 = "big"; String str2 = "small"; System.out.print("This is a " + str1 + " dog.\n"); System.out.print("That is a " + str2 + " cat.\n"); } }
This is a big dog.
That is a small cat.
public class BasicQuotation2
{
public static void main(String[] args) { char ch1 = 'A'; char ch2 = 'D'; System.out.print("This is " + ch1 + " team.\n"); System.out.print("That is " + ch2 + " team.\n"); } }
This is A team.
That is D team. |
|
|
| ご意見箱コーナー (管理者宛てメール) |
|
このページは、あなたの参考になりましたか? |