Code Monkey home page Code Monkey logo

Comments (7)

taooceros avatar taooceros commented on May 18, 2024

顺便小问一下,为什么重启翻译出来时ZhongQi hhhhhh

from toolgood.words.pinyin.

taooceros avatar taooceros commented on May 18, 2024

提供一个可行的方案,但是有一点丑陋

 var resultList = WordsHelper.GetPinyinList(content);

List<int> chineseIndexs = new List<int>();

for (int i = 0; i < content.Length; i++)
{
         if (resultList[i].Length != 1 || !(resultList[i][0] == content[i]))
         chineseIndexs.Add(i);
}
int currentChineseIndex = 0;
int lastChineseIndex = -1;
for (int i = 0; i < resultList.Length; i++)
{
    if (currentChineseIndex < chineseIndexs.Count && chineseIndexs[currentChineseIndex] == i)
    {
        resultBuilder.Append(' ');

        resultBuilder.Append(resultList[i]);
        currentChineseIndex++;
        lastChineseIndex = i;
    }
 else
  {
     if (i == lastChineseIndex + 1)
     {
         resultBuilder.Append(' ');
     }
     resultBuilder.Append(resultList[i]);
   }
 }

from toolgood.words.pinyin.

toolgood avatar toolgood commented on May 18, 2024

顺便小问一下,为什么重启翻译出来时ZhongQi hhhhhh

拼音库不全,所以会出现这个问题

from toolgood.words.pinyin.

toolgood avatar toolgood commented on May 18, 2024
        var pys = PinyinDict.GetPinyinList(text, tone ? 1 : 0);
        StringBuilder stringBuilder = new StringBuilder();
        bool pre = false;

        for (int i = 0; i < text.Length; i++) {
            var py = pys[i];
            if (py.Length > 1 || (text[i] >= 0x3400 && text[i]<= 0x9FD5)) { 
                if (stringBuilder.Length > 0) {
                    stringBuilder.Append(' ');
                }
                stringBuilder.Append(py);
                pre = true;
            } else {
                if (pre) {
                    stringBuilder.Append(' ');
                }
                stringBuilder.Append(text[i]);
                pre = false;
            }
        }
        return stringBuilder.ToString();

from toolgood.words.pinyin.

toolgood avatar toolgood commented on May 18, 2024

if (py.Length > 1 || (text[i] >= 0x3400 && text[i]<= 0x9FD5)) {
可以再次简化
if (text[i] >= 0x3400 && text[i]<= 0x9FD5) {

from toolgood.words.pinyin.

taooceros avatar taooceros commented on May 18, 2024

谢谢!

from toolgood.words.pinyin.

zhongshuiyuan avatar zhongshuiyuan commented on May 18, 2024

是不是没有合并到主版本啊,我的也会这样,英文被拆成了单个字母。

from toolgood.words.pinyin.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.