# insert

Definition: | sequence res = insert(sequence src, object what, integer index)
Description: | Insert an object into a sequence as a new element at a given location. target: the sequence to insert into what: the object to insert index: the position in target where what should appear Returns a sequence, which is target with one more element at index, which is what.
pwa/p2js: | Supported, but not particularly recommended.
Comments: | The length of the returned sequence is always length(src) + 1. Inserting a sequence into a string returns a dword-sequence, which is no longer a string. This routine, defined in builtins\pseqc.e (an autoinclude), is simply `src = src[1..index-1] & '0' & src[index..length(src)]; src[index] = what; return src` and is provided only for compatibility with Euphoria.
Example: |
    s = insert("John Doe", " Middle", 5)    -- s is {’J’,’o’,’h’,’n’," Middle",’ ’,’D’,’o’,’e’}
    s = insert({10,30,40}, 20, 2)           -- s is {10,20,30,40}
Implementation: | See builtins\pseqc.e (an autoinclude) for details of the actual implementation.