使用javascript组合unicode字符

combine unicode characters using javascript

本文关键字:字符 unicode 组合 javascript 使用      更新时间:2023-09-26

我可以使用这个

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

但是它像这样分割所有的字符

क,स,ौ,ट,ी

如何合并स,ौ得到सौ

ट,ी得到टी

问题是我想先拆分字符然后重新连接,这些是印度语中的连词,需要这样显示

您需要为印地语字符创建一个unicode字典,这里是完整表的链接,这里是您如何在代码中完成它:

<!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>

请记住,必须创建字典,否则它将无法工作,因为没有它,印地语字符串将无法识别。