文字列関連

左詰め

Public Function LPad(ByVal Str As String, ByVal Pad As String, ByVal Length As Long) As String

    If Length > Len(Str) Then
        Str = String(Length - Len(Str), Pad) & Str
    End If
    LPad = Str

End Function

右詰め

Public Function RPad(ByVal Str As String, ByVal Pad As String, ByVal Length As Long) As String

    If Length > Len(Str) Then
        Str = Str & String(Length - Len(Str), Pad)
    End If
    RPad = Str
    
End Function

左除去

Public Function LSup(ByVal Str As String, ByVal Sup As String) As String

    Dim SupLen As Long
    SupLen = Len(Sup)
    
    Dim i As Long
    For i = 1 To Len(Str) Step SupLen
        If Mid$(Str, i, SupLen) <> Sup Then
            Str = Mid$(Str, i)
            Exit For
        End If
    Next
    LSup = Str

End Function

右除去

Public Function RSup(ByVal Str As String, ByVal Sup As String) As String

    Dim SupLen As Long
    SupLen = Len(Sup)
    
    Dim i As Long
    For i = Len(Str) - SupLen + 1 To 1 Step -SupLen
        If Mid$(Str, i, SupLen) <> Sup Then
            Str = Left$(Str, i + SupLen - 1)
            Exit For
        End If
    Next
    RSup = Str

End Function

Null文字以降除去

Public Function StripNulls(ByVal Str As String) As String
    
    If InStr(Str, Chr(0)) > 0 Then
        Str = Left$(Str, InStr(Str, Chr(0)) - 1)
    End If
    StripNulls = Str

End Function


  • 最終更新:2012-10-20 15:36:44

このWIKIを編集するにはパスワード入力が必要です

認証パスワード