<small id='jq9eM'></small><noframes id='jq9eM'>

      <bdo id='jq9eM'></bdo><ul id='jq9eM'></ul>

    1. <legend id='jq9eM'><style id='jq9eM'><dir id='jq9eM'><q id='jq9eM'></q></dir></style></legend>

      <tfoot id='jq9eM'></tfoot>

      1. <i id='jq9eM'><tr id='jq9eM'><dt id='jq9eM'><q id='jq9eM'><span id='jq9eM'><b id='jq9eM'><form id='jq9eM'><ins id='jq9eM'></ins><ul id='jq9eM'></ul><sub id='jq9eM'></sub></form><legend id='jq9eM'></legend><bdo id='jq9eM'><pre id='jq9eM'><center id='jq9eM'></center></pre></bdo></b><th id='jq9eM'></th></span></q></dt></tr></i><div id='jq9eM'><tfoot id='jq9eM'></tfoot><dl id='jq9eM'><fieldset id='jq9eM'></fieldset></dl></div>
      2. 带有变音符号的 Unicode 字符串,按字符分割

        时间:2023-08-07
        • <bdo id='A0Uph'></bdo><ul id='A0Uph'></ul>

            <small id='A0Uph'></small><noframes id='A0Uph'>

            <tfoot id='A0Uph'></tfoot>
            1. <i id='A0Uph'><tr id='A0Uph'><dt id='A0Uph'><q id='A0Uph'><span id='A0Uph'><b id='A0Uph'><form id='A0Uph'><ins id='A0Uph'></ins><ul id='A0Uph'></ul><sub id='A0Uph'></sub></form><legend id='A0Uph'></legend><bdo id='A0Uph'><pre id='A0Uph'><center id='A0Uph'></center></pre></bdo></b><th id='A0Uph'></th></span></q></dt></tr></i><div id='A0Uph'><tfoot id='A0Uph'></tfoot><dl id='A0Uph'><fieldset id='A0Uph'></fieldset></dl></div>

                  <tbody id='A0Uph'></tbody>

                  <legend id='A0Uph'><style id='A0Uph'><dir id='A0Uph'><q id='A0Uph'></q></dir></style></legend>
                • 本文介绍了带有变音符号的 Unicode 字符串,按字符分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有这个 Unicode 字符串:Аа́Ббб́Ввв́Г㥴Дд

                  I have this Unicode string: Ааа́Ббб́Ввв́Г㥴Дд

                  我想用字符分割它.现在,如果我尝试循环所有字符,我会得到这样的结果:
                  A a a ' Б ...

                  And I want to it split by chars. Right now if I try to loop truth all chars I get something like this:
                  A a a ' Б ...

                  有没有办法将此字符串正确拆分为字符:А а́?

                  Is there a way to properly split this string to chars: А а а́ ?

                  推荐答案

                  要正确执行此操作,您需要的是计算字素簇边界的算法,如 UAX 29.不幸的是,这需要从 Unicode 字符数据库中了解哪些字符是哪些类的成员,而 JavaScript 不提供该信息(*).因此,您必须在脚本中包含 UCD 的副本,这会使其非常庞大.

                  To do this properly, what you want is the algorithm for working out the grapheme cluster boundaries, as defined in UAX 29. Unfortunately this requires knowledge of which characters are members of which classes, from the Unicode Character Database, and JavaScript doesn't make that information available(*). So you'd have to include a copy of the UCD with your script, which would make it pretty bulky.

                  如果您只需要担心拉丁语或西里尔语使用的基本重音,另一种选择是仅使用组合变音符号块 (U+0300-U+036F).这对于其他语言和符号可能会失败,但对于您想要做的事情可能就足够了.

                  An alternative if you only need to worry about the basic accents used by Latin or Cyrillic would be to take only the Combining Diacritical Marks block (U+0300-U+036F). This would fail for other languages and symbols, but might be enough for what you want to do.

                  function findGraphemesNotVeryWell(s) {
                      var re= /.[u0300-u036F]*/g;
                      var match, matches= [];
                      while (match= re.exec(s))
                          matches.push(match[0]);
                      return matches;
                  }
                  
                  findGraphemesNotVeryWell('Ааа́Ббб́Ввв́Г㥴Дд');
                  ["А", "а", "а́", "Б", "б", "б́", "В", "в", "в́", "Г", "г", "Ґ", "ґ", "Д", "д"]
                  

                  (*: 可能有一种方法可以通过让浏览器呈现字符串并测量其中的选择位置来提取信息...但这肯定会非常混乱和困难让跨浏览器工作.)

                  (*: there might be a way to extract the information by letting the browser render the string, and measuring the positions of selections in it... but it would surely be very messy and difficult to get working cross-browser.)

                  这篇关于带有变音符号的 Unicode 字符串,按字符分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 JavaScript 中使用模运算符 (%)? 下一篇:英文字母中哪个字母占用的像素最多?

                  相关文章

                  最新文章

                • <tfoot id='brK2F'></tfoot>

                  1. <small id='brK2F'></small><noframes id='brK2F'>

                    <i id='brK2F'><tr id='brK2F'><dt id='brK2F'><q id='brK2F'><span id='brK2F'><b id='brK2F'><form id='brK2F'><ins id='brK2F'></ins><ul id='brK2F'></ul><sub id='brK2F'></sub></form><legend id='brK2F'></legend><bdo id='brK2F'><pre id='brK2F'><center id='brK2F'></center></pre></bdo></b><th id='brK2F'></th></span></q></dt></tr></i><div id='brK2F'><tfoot id='brK2F'></tfoot><dl id='brK2F'><fieldset id='brK2F'></fieldset></dl></div>

                    1. <legend id='brK2F'><style id='brK2F'><dir id='brK2F'><q id='brK2F'></q></dir></style></legend>

                      • <bdo id='brK2F'></bdo><ul id='brK2F'></ul>