Vixual / 123 posts / tags / 80 comments / feed / comments feed /
Search:

[轉載]Unicode 脫逸序列轉換

轉載自: IT Inside


這裡提供一段程式碼,可以透過 JavaScript 將文字轉換為 Unicode 脫逸序列。這段程式碼,不論是對網頁開發人員,還是對 java resource bundle 的翻譯人員,都有很大的方便性。使用時只要將底下的程式碼複製起來,以 html 副檔名儲存,就可以用 browser 執行了。

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
<script language=javascript>
<!--
function StringToUniCode(source) {
  sret = "";
  // Unicode 跳脫序列之格式為 \u00ff
  for(var i=0; i < source.length; i++) {
   var num = new Number( source.charCodeAt(i));
   sret += "\\u" + num.toString(16);
  }
  return sret;
}
function convert(){
  document.forms.content.result.value = StringToUniCode(document.forms.content.source.value);
}
//-->
</script>
將文字轉成 Unicode 跳脫序列
<form name=content>
來源:<input type=TEXT name=source size=40 value="常用連絡人"><br />
結果:<input type=TEXT name=result size=40><br />
<input type=button value=轉換 onclick="convert()">
</form>
收藏至網路書籤: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Google
  • Live
  • YahooMyWeb
  • MyShare
  • Hemidemi
  • Funp

您可能會對以下這些文章感興趣

您對這篇文章的評價:
1 Star2 Stars3 Stars4 Stars5 Stars (有 1 人給予評價)
Loading ... Loading ...

沒有任何留言

發表您的評論

(您的留言會在審核後才能公開)