[英]Check if string is UTF-8 returning \u+hex if so, false if not
[英]Convert percentage symbols to u+hex (javascript)
我需要替換已解碼的字符串,該字符串的百分比符號為U + hex。
串:
"text=%F0%9F%98%8A&id=60&tags=";
我需要的:
根據http://unicode.org/emoji/charts/full-emoji-list.html ,將%F0%9F%98%8A
更改為'U+1F60A'
或1F60A
(全局)。
對於1f60a
:
var c = decodeURIComponent("%F0%9F%98%8A").codePointAt(0).toString(16);
注意\ὠa
在JS中不起作用(盡管它將作為HTML實體),但您需要2個代碼點; c.charCodeAt(0).toString(16)
和c.charCodeAt(1).toString(16)
var message = "This is my message %F0%9F%98%8A and I love emojis!"; $("p").text(decodeURI(message));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p></p>
var消息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.