dsdt66064367 2013-11-06 14:19
浏览 71
已采纳

组合或构造韩文字母

Is there anyway that I can combine this Korean consonants and vowels into a complete character.

For example if I have

  ㄱㅏㅁㅅㅏㅎㅏㅂㄴㅣㄷㅏ

It would be

  감사합니다

Is there any way to do this? I can only think of bruteforcing every case that would have to count many many cases.

Below is my try. Not optimal and take too much time.

if strings.Contains(input_str, "ㅏㄴㅈ") {
    input_str = strings.Replace(input_str, "ㅇㅏㄴㅈ", "앉", -1)
}

if strings.Contains(input_str, "ㅏㄹㅂ") {
    input_str = strings.Replace(input_str, "ㅂㅏㄹㅂ", "밟", -1)
}

if strings.Contains(input_str, "ㅏㅂㅅ") {
    input_str = strings.Replace(input_str, "ㄱㅏㅂㅅ", "값", -1)
}
  • 写回答

2条回答 默认 最新

  • douzhao4071 2013-11-06 15:58
    关注

    What you want is Unicode normalization to compose hangul jamo. Go supports this but not (yet) in the standard library. See this related issue.

    To import the external go.text/unicode/norm package use:

    go get -u golang.org/x/text/unicode/norm
    

    You probably want to use NFC which does a

    • Canonical Decomposition,
    • followed by Canonical Composition (which is what you want)

    Example for NFD (decomposition):

    // 앉 -> 앉
    fmt.Println( string( norm.NFD.AppendString(nil, "앉") ) )
    

    Example for NFC (composition):

    // 앉 -> 앉
    fmt.Println( string( norm.NFC.AppendString(nil, "앉") ) )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题