■  文字列バイト数取得

レングスじゃなく、バイト数を取得する例です。

【func_GetByte】
Imports System.Text
Module xxxxx

    Function func_GetByte(ByRef strSTRING As String) As Integer
        Dim ascii As Encoding = Encoding.GetEncoding("Shift_Jis")
        Dim intLen As Integer
        intLen = 0
        Try
            intLen = ascii.GetByteCount(strSTRING)
        Catch ex As Exception
            intLen = 0
        End Try
        func_GetByte = intLen
    End Function

func_GetByteを呼ぶ側

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                                                                      Handles Button3.Click
        Dim moji As Integer
        moji = func_GetByte(Me.TextBox1.Text)
        MessageBox.Show(moji.ToString)
    End Sub

Encoding.GetEncoding("Shift_Jis")を使用するにはImports System.Textが必要です。

※半角と全角が混在していてもOKです。


BEFORE PAGE

TOP PAGE