使用javascript组合unicode字符

时间:2015-05-17 13:57:03

标签: javascript unicode

我可以使用此

分割unicode字符
function myFunction() {
    var str = "कसौटी";
    var res = str.split("");
    document.getElementById("demo").innerHTML = res;

然而它会分割所有这样的字符

क,स,ौ,ट,ी

如何合并स,ौ以获取सौ

ट,ी获取टी

问题是我想首先拆分字符然后重新加入它们,这些是印地语中的合取并需要以这种方式呈现

1 个答案:

答案 0 :(得分:0)

您需要为印地语字符创建一个unicode字典,这里是full table的链接,以下是您在代码中的操作方法:

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
     var theDictionary = {'\u0bbf':true,'\u0bcd':true,...}; //example of unicode, add yours
     var temporaryList ="कसौटी".split('');
    var targetList = [];
    for(var index in temporaryList ){
      if(theDictionary [temporaryList [index]])
      {
        targetList[targetList.length - 1] +=  temporaryList [index];
      }
      else
      {
        targetList.push(temporaryList [index]);
      }
    }
}
</script>
</head>

<body>

<h1>My Web Page</h1>

<p id="demo">A Paragraph</p>

<button type="button" onclick="myFunction()">Try it</button>

</body>
</html>

请记住,必须创建字典,否则它将无效,因为没有它,将无法识别hindi字符串。

相关问题