文字列追加

指定した文字を追加する。
区切り文字指定、除外文字列指定、重複チェック指定、追加位置指定あり。
## 引数情報指定
~~~
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 文字列追加
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 引数情報初期化
'------------------------------------------------------------------------------
Public Property Get G_String_InitArgAddInf() As T_STRING_ARG_ADD_INF
    Dim wkInf As T_STRING_ARG_ADD_INF
    
    With wkInf
        .Target = ""
        
        .Dlmt = ""
        .DlmtChkFlg = True
        
        .Add = ""
        .AddChkFlg = False
        .AddSpec = E_STRING_SPEC_POS_END
        
        .Excluded = ""
    End With
    
    G_String_InitArgAddInf = wkInf
End Property


'------------------------------------------------------------------------------
' 文字列追加（引数情報指定）
'------------------------------------------------------------------------------
Public Function F_String_ReturnAdd_Inf( _
        ByRef aArgInf As T_STRING_ARG_ADD_INF) As String
    Dim wkRtn As String
    
    Dim wkAddChkFlg As Boolean
    Dim wkTmpStr As String
    
    With aArgInf
        '初期化
        wkRtn = .Target
        wkAddChkFlg = .AddChkFlg
        
        '追加ありの場合
        If .Add <> "" Then
            '区切り文字接続
            If wkRtn = "" Then
                '追加元が無い場合は無視
            ElseIf PF_String_GetAdd_Sub(wkRtn, .Dlmt, .AddSpec, .DlmtChkFlg, .Excluded) = True Then
                '区切り追加した場合は追加チェックを有効化
                wkAddChkFlg = True
            End If
            
            '追加文字接続
            PF_String_GetAdd_Sub wkRtn, .Add, .AddSpec, wkAddChkFlg, .Excluded
        End If
    End With
    
    F_String_ReturnAdd_Inf = wkRtn
End Function

' サブルーチン
Private Function PF_String_GetAdd_Sub( _
        ByRef aRtn As String, _
        ByVal aAdd As String, ByVal aAddSpec As E_STRING_SPEC, _
        ByVal aAddChkFlg As Boolean, ByVal aExcluded As String) As Boolean
    Dim wkRet As Boolean: wkRet = True
    
    Dim wkChkStr As String
    Dim wkExcStr As String
    
    If aAdd <> "" Then
        If aAddChkFlg = True Then
            '追加位置が後方指定の場合
            If aAddSpec = E_STRING_SPEC_POS_END Then
                wkChkStr = Right(aRtn, Len(aAdd))
                If aExcluded <> "" Then
                    wkExcStr = Right(aRtn, Len(aExcluded))
                End If
            '追加位置が前方指定の場合
            Else
                wkChkStr = Left(aRtn, Len(aAdd))
                If aExcluded <> "" Then
                    wkExcStr = Left(aRtn, Len(aExcluded))
                End If
            End If
            
            '接続位置に文字がある場合
            If StrComp(wkChkStr, aAdd, vbBinaryCompare) = 0 Then
                '対象外文字が無い場合は追加対象外
                If aExcluded = "" Then
                    wkRet = False
                '対象外文字と不一致の場合は追加対象外
                ElseIf StrComp(wkExcStr, aExcluded, vbBinaryCompare) <> 0 Then
                    wkRet = False
                End If
            End If
        End If
        
        '追加ありの場合
        If wkRet = True Then
            '追加位置指定に従って文字列追加
            If aAddSpec = E_STRING_SPEC_POS_END Then
                aRtn = aRtn & aAdd
            Else
                aRtn = aAdd & aRtn
            End If
        End If
    End If
    
    PF_String_GetAdd_Sub = wkRet
End Function
~~~
## 引数指定
~~~
'------------------------------------------------------------------------------
' 文字列追加（引数指定）
'------------------------------------------------------------------------------
Public Function F_String_ReturnAdd( _
        ByVal aTarget As String, ByVal aAdd As String, _
        Optional ByVal aDlmt As String = "", _
        Optional ByVal aAddSpec As E_STRING_SPEC = E_STRING_SPEC_POS_END, _
        Optional ByVal aExcluded As String = "") As String
    Dim wkArgInf As T_STRING_ARG_ADD_INF: wkArgInf = G_String_InitArgAddInf()
    
    With wkArgInf
        .Target = aTarget
        .Dlmt = aDlmt
        .Add = aAdd
        .AddSpec = aAddSpec
        .Excluded = aExcluded
    End With
    
    F_String_ReturnAdd = F_String_ReturnAdd_Inf(wkArgInf)
End Function
~~~