Quisiera estar en otro lugar
seen from Hong Kong SAR China
seen from United States
seen from United States

seen from Brazil
seen from United States

seen from Canada

seen from Germany
seen from Germany
seen from United States
seen from Germany
seen from Canada

seen from United States

seen from United States
seen from United States
seen from Germany
seen from Germany
seen from Germany
seen from Australia
seen from United States
seen from Australia
Quisiera estar en otro lugar
#unescape b/n
#playahermosa #playitarica #porquéno #unescape
Lo mas gracioso es que quiero dejar de pensar en eso que me esta matando, y de alguna manera termino recordándolo de nuevo, como si todo lo que viera me hablara de eso.
What is a JavaScript unescape equivalent using Ruby?
What is a JavaScript unescape equivalent using Ruby?
I want to unescape the following string:
'\u00020\u0002Standard\u00023\u0002Doe John\u000169\u0002\u0010\u0002Lorem\u0002\u0011\u0002Ipsum\u0002\u0014\u0002'
Javascript’s unescape function works OK, however how can I unescape it in Ruby?
If I unescape the string above, it will result in “0Standard3Doe John69LoremIpsum“.
Best Answer
It seems to me that you’re using Ruby 1.8, so you have poor…
View On WordPress
“A free online tool to escape or unescape JavaScript strings.”
突然ですが、以下のコードで何が表示されるでしょうか? unicodeを勝手に置き換えてくれる alert("S\u0026M"); 「S&M」と表示されます。 JavaScriptでは\uXXXXという文字列をunicodeと判断して勝手に置き換えてくれます。 これなら特に問題ないのですが、例えばAJAXでJSON形式のデータを取得したときは、 「S\\u0026M」のようなデータが来ることがあります。 「\」が2個です。 これをそのまま表示すると…、 \が2個付いてると… alert("S\\u0026M"); 「S\u0026M」と表示されます。 最初の「\」が2個目の「\」をエスケープして、「u0026」はそのまま表示ってことでしょうか。 もちろん意図したものではありません。 「んだよ!要するに\が1個ならいいんだろ!」ってことで以下のように置換しようとしたら…、 \が1個ならいいんだろ! alert("S\\u0026M".replace("\\\\", "\\")); 今度は置換に引っかかりません。 内部的に「S\\u0026M」を解釈しようとしたときには既に「\」がエスケープされて1個になってるのでしょう。 ということでunicodeをunescapeする関数を作りましょう。 これが正解 alert(unescapeUnicode("S\\u0026MはRihannaの曲です。")); function unescapeUnicode(string) { return string.replace(/\\u([a-fA-F0-9]{4})/g, function(matchedString, group1) { return String.fromCharCode(parseInt(group1, 16)); }); } replace()の第2引数にfunctionを与えます。 これが置換のルールというか方法を司ります。 さてこのfunctionの引数ですが、上記の例だと2個しか書いていませんが本当は以下のようになっています。 1:正規表現にマッチした文字列(\\u0026) 2:正規表現の1個目のグループ(0026) 3:正規表現の2個目のグループ ~ n+1:正規表現のn個目のグループ n+2:マッチした文字列が何文字目にあるか(1) n+3:検索した文字列全体(S\\u0026MはRihannaの曲です。) 第2引数から第n+1引数までは、グループ数によって可変長です。 常識的に考えて、可変長の部分は引数リストの最後だろうが! なんで真ん中に置くんだよ! replace()以外で特にめぼしいところはありません。 parseInt()で16進の整数に変換し、fromCharCode()でそれを文字に変換します。
JavaScriptでunicode文字列をunescapeする: ぺるたごブログ