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