文字列関数

ページ名:文字列関数

''' <summary>
''' 文字列関数
''' </summary>
''' <remarks></remarks>
Module mdlStringFunction

    Public Function pf_LenB(ByVal wp_String As String) As Integer
        Dim ret As Integer = 0
        If wp_String <> "" Then
            ret = System.Text.Encoding.GetEncoding("Shift_JIS").GetByteCount(wp_String)
        End If
        Return ret
    End Function

    Public Function pf_LeftB(ByVal wp_String As String, ByVal wp_Length As Integer) As String
        Dim ret As String = ""
        Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
        Dim b As Byte() = enc.GetBytes(wp_String.PadRight(wp_Length))
        ret = enc.GetString(b, 0, wp_Length)
        Return ret
    End Function

    Public Function pf_RightB(ByVal wp_String As String, ByVal wp_Length As Integer) As String
        Dim ret As String = ""
        Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
        Dim b As Byte() = enc.GetBytes(wp_String.PadLeft(wp_Length))
        Dim i As Integer = UBound(b) + 1 - wp_Length
        ret = enc.GetString(b, i, wp_Length)
        Return ret
    End Function

    Public Function pf_MidB(ByVal wp_String As String, ByVal wp_Start As Integer) As String
        Dim ret As String = ""
        Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
        Dim w_Length As Integer = pf_LenB(wp_String) - wp_Start + 1
        Dim b As Byte() = enc.GetBytes(wp_String.PadRight(wp_Start + w_Length))
        ret = enc.GetString(b, wp_Start - 1, w_Length)
        Return ret
    End Function

    Public Function pf_MidB(ByVal wp_String As String, ByVal wp_Start As Integer, ByVal wp_Length As Integer) As String
        Dim ret As String = ""
        Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
        Dim b As Byte() = enc.GetBytes(wp_String.PadRight(wp_Start + wp_Length))
        ret = enc.GetString(b, wp_Start - 1, wp_Length)
        Return ret
    End Function

End Module
 

シェアボタン: このページをSNSに投稿するのに便利です。

コメント

返信元返信をやめる

※ 悪質なユーザーの書き込みは制限します。

最新を表示する

NG表示方式

NGID一覧