指定文字列間取得

# 指定文字列間取得
指定した文字列から、開始文字と終了文字の間を返却する。
開始文字前追加指定、検索文字追加指定あり
## 引数情報指定
~~~
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 指定文字列間取得
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 引数情報初期化
'------------------------------------------------------------------------------
Public Property Get G_String_InitArgGetInf() As T_STRING_ARG_GET_INF
    Dim wkInf As T_STRING_ARG_GET_INF
    
    With wkInf
        .SrchInf = G_String_InitArgSrchInf
        
        .SttStr = ""
        .EndStr = ""
        
        .AddBefFlg = False
        .AddSrchFlg = False
    End With
    
    G_String_InitArgGetInf = wkInf
End Property

'------------------------------------------------------------------------------
' 指定文字列間取得（引数情報指定）
'------------------------------------------------------------------------------
Public Function F_String_GetMidStr_Inf( _
        ByRef aRtn As String, _
        ByRef aArgInf As T_STRING_ARG_GET_INF) As Boolean
    Dim wkRet As Boolean
    Dim wkRtn As String
    
    Dim wkSttInfAry As Variant, wkSttInf As Variant
    Dim wkEndInfAry As Variant, wkEndInf As Variant
    Dim wkArgSrchInf As T_STRING_ARG_SEARCH_INF
    
    Dim wkSttCnt As Long, wkSttNow As Long
    Dim wkChkCnt As Long
    
    Dim wkGetSttInf As Variant
    Dim wkGetEndInf As Variant
    Dim wkGetSttPos As Long, wkGetEndPos As Long
    
    With aArgInf
        wkArgSrchInf = aArgInf.SrchInf
        
        wkArgSrchInf.Search = .SttStr
        '開始位置取得（引数チェック兼用）
        If F_String_GetSearchInfArray_Inf(wkSttInfAry, wkArgSrchInf) <> True Then
            Exit Function
        End If
        
        wkArgSrchInf.Search = .EndStr
        '終了位置取得（引数チェック兼用）
        If F_String_GetSearchInfArray_Inf(wkEndInfAry, wkArgSrchInf) <> True Then
            Exit Function
        End If
    End With
    
    '終了位置で全ループ
    wkSttNow = LBound(wkSttInfAry) - 1
    For Each wkEndInf In wkEndInfAry
        '開始位置でループ
        For wkSttCnt = wkSttNow + 1 To UBound(wkSttInfAry)
            wkSttInf = wkSttInfAry(wkSttCnt)
            
            '開始位置が終了位置以上の場合はループ終了
            If wkSttInf(E_STRING_IDX_SRCH_INF_POS_START) >= wkEndInf(E_STRING_IDX_SRCH_INF_POS_START) Then
                Exit For
            End If
            
            '各種更新
            wkSttNow = wkSttCnt
            wkChkCnt = wkChkCnt + 1
            
            '初回の場合は開始位置保持
            If IsArray(wkGetSttInf) <> True Then
                wkGetSttInf = wkSttInf
            End If
        Next wkSttCnt
        
        '開始位置が見つかっている場合は終了位置チェック
        If IsArray(wkGetSttInf) = True Then
            wkChkCnt = wkChkCnt - 1
            
            '整合が取れた場合はループ終了
            If wkChkCnt <= 0 Then
                wkGetEndInf = wkEndInf
                wkRet = True
                Exit For
            End If
        End If
    Next wkEndInf
    
    '取得あり時は文字列返却
    If wkRet = True Then
        With aArgInf
            '開始位置調整
            '検索前文字列追加指定ありの場合
            If .AddBefFlg = True Then
                wkGetSttPos = .SrchInf.SttPos
            '検索文字列追加指定なしの場合
            ElseIf .AddSrchFlg <> True Then
                wkGetSttPos = wkGetSttInf(E_STRING_IDX_SRCH_INF_POS_START) + wkGetSttInf(E_STRING_IDX_SRCH_INF_LENGTH)
            End If
        
            '終了位置調整
            '検索前文字列追加指定あり、または検索文字列追加指定ありの場合
            If .AddBefFlg = True Or .AddSrchFlg = True Then
                wkGetEndPos = wkGetEndInf(E_STRING_IDX_SRCH_INF_POS_START) - wkGetEndInf(E_STRING_IDX_SRCH_INF_LENGTH) + 1
            '文字列追加指定なしの場合
            Else
                wkGetEndPos = wkGetEndInf(E_STRING_IDX_SRCH_INF_POS_START) - 1
            End If
            
            If wkGetSttPos <= wkGetEndPos Then
                wkRtn = Mid(.SrchInf.Target, wkGetSttPos, (wkGetEndPos - wkGetSttPos + 1))
            End If
        End With
        
        If wkRtn <> "" Then
            aRtn = wkRtn
            F_String_GetMidStr_Inf = True
        End If
    End If
End Function
~~~
## 引数指定
~~~
'------------------------------------------------------------------------------
' 指定文字列間取得（引数指定）
'------------------------------------------------------------------------------
Public Function F_String_GetMidStr( _
        ByRef aRtn As String, _
        ByVal aTarget As String, _
        ByVal aSttStr As String, ByVal aEndStr As String, _
        Optional ByVal aAddBefFlg As Boolean = False, _
        Optional ByVal aAddSrchFlg As Boolean = False) As Boolean
    Dim wkArgInf As T_STRING_ARG_GET_INF: wkArgInf = G_String_InitArgGetInf()
    
    With wkArgInf
        With .SrchInf
            .Target = aTarget
            .GetIdx = D_IDX_START
        End With
        
        .SttStr = aSttStr
        .EndStr = aEndStr
        .AddBefFlg = aAddBefFlg
        .AddSrchFlg = aAddSrchFlg
    End With
    
    F_String_GetMidStr = F_String_GetMidStr_Inf(aRtn, wkArgInf)
End Function
~~~