Ada*_*rer 6 javascript internationalization
我很好奇为什么以下占位符替换从右到左的语言(这些是随机的阿拉伯字符)会导致格式化的字符串反转所有单词.
'{0} ?????????'.replace('{0}', '????')
=> "???? ?????????"
Run Code Online (Sandbox Code Playgroud)
在最新的Chrome,FF和Safari中观察到此行为.它使Node中的单词顺序保持不变.
没有。replace完全按照您的要求执行操作:用替换该字符串的前三个字母????。我将其设置为四个而不是三个,以便原始和替换的长度相同(从而更容易看到发生了什么情况):
var before = '{00} ?????????';
var rep = '????';
var after = before.replace('{00}', rep);
console.log("before", before.split("").map(toCharCode).join(", "));
console.log("rep ", rep.split("").map(toCharCode).join(", "));
console.log("after ", after.split("").map(toCharCode).join(", "));
function toCharCode(c) {
var hex = c.charCodeAt(0).toString(16);
hex = "0000".substr(hex.length - 4) + hex;
return "U-" + hex;
}Run Code Online (Sandbox Code Playgroud)
输出:
在U-007b,U-0030,U-0030,U-007d,U-0020,U-062a,U-0643,U-0646,U-0648,U-0644,U-0648,U-062c,U -064a,U-0627 代表U-0647,U-0644,U-0647,U-0644 在U-0647,U-0644,U-0647,U-0644,U-0020,U-062a,U-0643,U-0646,U-0648,U-0644,U-0648,U-062c,U之后-064a,U-0627
请注意,替换序列(U-0647,U-0644,U-0647,U-0644)现在位于字符串的开头。
您所看到的是字符串的显示方式。因为RTL字符的连续范围是从右到左显示的,所以您现在有一个RTL范围,它以这种方式显示:替换在开头(最右边),文本继续在左边。以前,您对LTR和RTL有误,这与LTR(从左至右显示)和RTL(从右至左显示)一起显示。
| 归档时间: |
|
| 查看次数: |
509 次 |
| 最近记录: |