2017年10月25日 星期三

網頁計算字元數字(bytes)

https://www.puritys.me/docs-blog/article-107-String-Length-%E4%B8%AD%E6%96%87%E5%AD%97%E4%B8%B2%E9%95%B7%E5%BA%A6.html
  1. tx = "測式中文xxxx";
  2. var str = encodeURIComponent(tx);
  3. console.log("utf8:"+str);
  4. len = str.replace(/%[A-F\d]{2}/g, 'U').length;
  5. console.log("len = "+len);