開発環境
- OS X Lion - Apple(OS)
- Safari (Webプラウザ)
- TextWrangler(Text Editor) (BBEditの無料、light版)
- Script言語:JavaScript
- JavaScript Library: jQuery
『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-84312-225-5) の2章(JavaScriptのデータ型と変数)練習問第2-3を解いてみる。
その他参考書籍
- JavaScript 第6版
- JavaScriptリファレンス 第6版
- 『jQueryクックブック』(jQuery Community Experts 著、株式会社クイープ 訳、オライリー・ジャパン、2010年、ISBN978-4-87312-268-2)
2-3.
有効な文字列ではない。ダブルクォートで囲んで文字列中のダブルクォートをエスエープする場合とシングルクォートで囲んで文字列中のシングルクォートをエスケープする場合。
コード(TextWrangler)
var str1 = "Who once said, \"Only two things are infinite, " + "the universe and human stupidity, " + "and I'm not sure about the former.\""; var str2 = 'Who once said, "Only two things are infinite, ' + 'the universe and human stupidity, ' + 'and I\'m not sure about the former."'; var result = str1 + "\n" + str2; $('#pre0').text(result);
ちなみにPythonの場合。
コード(TextWrangler)
sample.py
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- str1 = "Who once said, \"Only two things are infinite, " + \ "the universe and human stupidity, " + \ "and I'm not sure about the former.\"" str2 = 'Who once said, "Only two things are infinite, ' + \ 'the universe and human stupidity, ' + \ 'and I\'m not sure about the former."' print(str1,str2, sep="\n")
入出力結果(Terminal)
$ ./sample.py Who once said, "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." Who once said, "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." $
0 コメント:
コメントを投稿