Function String Manipulations Class

InsertString

Insert one string into the middle of another string and return the results. vSource is inserted into vDest before character position vInsertPosition.

Signature (Visual Basic / VBA)

Public Function InsertString( _
      ByVal vDest As Variant _
    , ByVal vSource As Variant _
    , Optional ByVal vInsertPosition As Variant _
    ) As Variant

Code Example

    InsertString("123456", "NEW", 3) = "12NEW3456"

Parameters

Parameter Description
vDest The string into which the other string is to be inserted. vDest defaults to an empty string if it is Null or cannot be fixed up to a String.
vSource The string which is to be inserted into the other string. vSource defaults to an empty string if it is Null or cannot be fixed up to a String.
vInsertPosition The character position within vDest before which vSource will be inserted. vInsertPosition defaults to 1 (one) if missing or Null or cannot be fixed up to a number. vSource is inserted at the beginning of vDest if vInsertPosition is < 1 (less than one). vSource is inserted after the end of vDest if vInsertPosition is greater than the length of vDest.

Notes & Version History

Summary Similar to the StrIns subroutine, except that this is a function which returns the result instead of modifying an argument. Function returns Null if both strings (vDest and vSource) are Null.