0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

文字列分割

Last updated at Posted at 2025-04-22

文字列を指定文字で分割する

文字列分割

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 文字列分割
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Function F_String_GetSplit( _
        ByRef aRtnAry As Variant, _
        ByVal aStr As String, ByVal aDlmt As String, _
        Optional ByVal aIncChkFlg As Boolean = False) As Boolean
    Dim wkRtnAry As Variant
    
    '引数チェック
    If aStr = "" Or aDlmt = "" Then
        Exit Function
    End If
    
    '区切りで分割
    wkRtnAry = Split(aStr, aDlmt)
    
    '区切り包含チェックありの場合、区切り無しはNGで終了
    If aIncChkFlg = True Then
        If UBound(wkRtnAry) <= LBound(wkRtnAry) Then
            Exit Function
        End If
    End If
    
    aRtnAry = wkRtnAry
    F_String_GetSplit = True
End Function

拡張子指定分割

'------------------------------------------------------------------------------
' 拡張子指定分割
'------------------------------------------------------------------------------
Public Function F_String_GetSplitExtension( _
        ByRef aRtnAry As Variant, _
        ByVal aExtSpec As String) As Boolean
    Dim wkRtnAry As Variant
    Dim wkTmpAry As Variant, wkTmp As Variant
    
    '文字列分割(引数チェック兼用)
    If F_String_GetSplit(wkTmpAry, aExtSpec, ";") <> True Then
        Exit Function
    End If
    
    '分割全てループ
    For Each wkTmp In wkTmpAry
        '空白でなければ追加
        wkTmp = Trim(wkTmp)
        If wkTmp <> "" Then
            wkRtnAry = M_Common.F_ReturnArrayAdd(wkTmpAry, wkTmp)
        End If
    Next wkTmp
    
    If IsArray(wkRtnAry) = True Then
        aRtnAry = wkRtnAry
        F_String_GetSplitExtension = True
    End If
End Function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?