銀河鉄道

【VBA】文字列から、指定の文字をカットする|指定文字より前/後ろを残す

サムネイル
指定の文字より前/後ろをカット

文字をカットする

元の文字列から、指定文字より後ろの文字をカット|前を残す

Public Function CutAfterLastStr( _
                                        ByVal strSrc As String, _
                                        ByVal strCut As String) As String
    Dim num As Long
    num = InStrRev(strSrc, strCut)
    CutAfterLastStr = Left(strSrc, num - 1)
End Function

元の文字列から、指定文字より前の文字をカット|後ろを残す

Public Function CutBeforeLastStr( _
                                        ByVal strSrc As String, _
                                        ByVal strCut As String) As String
    Dim num As Long
    num = InStrRev(strSrc, strCut)
    CutBeforeLastStr = Mid(strSrc, num + 1)
End Function

空白をカットしたい場合

関連記事

著者

author
月うさぎ

編集後記:
この記事の内容がベストではないかもしれません。

記事一覧