Created
July 9, 2017 05:07
-
-
Save Y-Fujikawa/5045f1a08c6900fac3360a0529a96cb4 to your computer and use it in GitHub Desktop.
文字列リテラルのダブルクォートとシングルクォート
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ダブルクォート | |
# ・バックスラッシュ記法と式展開が有効になる | |
str1 = "式展開も試してみます" | |
puts "ダブルクォートのサンプル文字列です\n\nそして、#{str1}" | |
# 文字列内でダブルクォートを使いたい場合、エスケープ文字を入れる | |
# ※「サンプル文字」をダブルクォートで括ってみる | |
puts "ダブルクォートの\"サンプル文字列\"です\n\nそして、#{str1}" | |
# シングルクォート | |
# ・\\ (バックスラッシュそのもの)と \' (シングルクォート) を覗いて、文字列の中身の解釈しない | |
str2 = "式展開されないことを確認します" | |
puts 'シングルクォートのサンプル文字列です\n\nそして、#{str2}' | |
# シングルクォートの場合、中身の会社はしないのでエスケープ文字を入れなくてもそのまま表示される | |
puts 'シングルクォートの"サンプル文字列"です\n\nそして、#{str2}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment