0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

notes

Posted at

Function NormalizeKatakana(ByVal text As String) As String
Dim i As Integer
Dim result As String
result = ""

For i = 1 To Len(text)
    Dim ch As String
    ch = Mid(text, i, 1)
    Dim chCode As Integer
    chCode = AscW(ch)
    
    ' 次の文字が濁点 (゛: U+3099) または 半濁点 (゜: U+309A) の場合
    If i < Len(text) Then
        Dim nextCh As String
        nextCh = Mid(text, i + 1, 1)
        Dim nextChCode As Integer
        nextChCode = AscW(nextCh)
        
        If nextChCode = &H3099 Then ' 濁点゛
            If chCode >= &H30AB And chCode <= &H30DB And (chCode Mod 2 = 1) Then
                ch = ChrW(chCode + 1) ' カタカナの清音 → 濁音
                i = i + 1 ' 濁点をスキップ
            End If
        
        ElseIf nextChCode = &H309A Then ' 半濁点゜
            If chCode >= &H30CF And chCode <= &H30DB And (chCode Mod 2 = 1) Then
                ch = ChrW(chCode + 2) ' ハ行の清音 → 半濁音
                i = i + 1 ' 半濁点をスキップ
            End If
        End If
    End If
    
    result = result & ch
Next

NormalizeKatakana = result

End Function

' テスト用サブルーチン
Sub TestNormalize()
Dim testStr As String
testStr = "カ゛キ゛ク゛ケ゛コ゛_シ゛ス゛セ゛ソ゛_タ゛チ゛ツ゛テ゛ト゛_ハ゛ヒ゛フ゛ヘ゛ホ゛_ハ゜ヒ゜フ゜ヘ゜ホ゜"
Msgbox "Before: " & testStr & Chr(10) & "After: " & NormalizeKatakana(testStr)
End Sub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?