FUNCTIONS CORE

PosIns()

Insert character(s) at a specified position in a string

Syntax

Signature
PosIns( cString, cInsert, [nPos] ) --> cResult

Arguments

cString

cInsert

nPos

Example

PosIns.prg
PROCEDURE Main()

   LOCAL cDate := "20261102"

   Check( 'PosIns( "abcdefgh", "123", 2 )               ', PosIns( "abcdefgh", "123", 2 ), "a123bcdefgh" )
   Check( 'PosIns( "abcdefgh", "123", 8 )               ', PosIns( "abcdefgh", "123", 8 ), "abcdefg123h" )
   Check( 'PosIns( "abcdefgh", "123", 10 )              ', PosIns( "abcdefgh", "123", 10 ), "abcdefgh" )
   Check( 'PosIns( PosIns( cDate, "-", 7 ), "-", 5 )    ', PosIns( PosIns( cDate, "-", 7 ), "-", 5 ), "2026-11-02" )

RETURN

STATIC PROCEDURE Check( cTitle, xResult, xExpected )

   QOut( cTitle + IIF( xResult == xExpected, "OK", "ERROR" ) )

RETURN

Output

PosIns( "abcdefgh", "123", 2 )               OK
PosIns( "abcdefgh", "123", 8 )               OK
PosIns( "abcdefgh", "123", 10 )              OK
PosIns( PosIns( cDate, "-", 7 ), "-", 5 )    OK