How to classify Japanese characters as either kanji or kana?

后端 未结 5 913
既然无缘
既然无缘 2021-02-01 22:57

Given the text below, how can I classify each character as kana or kanji?

誰か確認上記これらのフ

To get some thing like this

誰 - kanji
か - kana
確 - kanji
認          


        
5条回答
  •  一生所求
    2021-02-01 23:38

    I know you didn't ask for VBA, but here is the VBA flavor for those who want to know:

    Here's a function that will do it. It will break down the sentence like you have above into a single cell. You might need to add some error checking for how you want to deal with line breaks or English characters, etc. but this should be a good start.

    Function KanjiKanaBreakdown(ByVal text As String) As String
    
    Application.ScreenUpdating = False
    Dim kanjiCode As Long
    Dim result As String
    Dim i As Long
    
    For i = 1 To Len(text)
        If Asc(Mid$(text, i, 1)) > -30562 And Asc(Mid$(text, i, 1)) < -950 Then
            result = (result & (Mid$(text, i, 1)) & (" - kanji") & vbLf)
        Else
            result = (result & (Mid$(text, i, 1)) & (" - kana") & vbLf)
        End If
    Next
    
    KanjiKanaBreakdown = result
    Application.ScreenUpdating = True
    
    End Function
    

提交回复
热议问题