VB.NET Check 2byte Characters (2バイトの文字チェック)


    Private Sub Check2ByteStirngs()
        Dim text As String = "aaあaa"
        'Shift JISに変換したときに必要なバイト数を返す
        Dim byte_len As Integer = System.Text.Encoding.GetEncoding(932).GetByteCount(text)
 
        If (text.Length <> byte_len) Then
            '2バイト文字発見
            For Each c As String In text
                If System.Text.Encoding.GetEncoding(932).GetByteCount(c) <> c.Length Then
                    MsgBox(c)
                End If
            Next
        End If
    End Sub

----------------------------------------
Result: あ