string insertTcl 9.1 only

Gives a string with text put before the character at an index.

string insert STRING INDEX TEXT

Description

Gives STRING with TEXT before the character at INDEX. The variable of STRING does not change.

An INDEX at or below 0 puts TEXT at the start. end puts TEXT after the last character, and so does each index past the end. An empty TEXT gives STRING.

The subcommand is in Tcl 9.1 only.

Arguments

ArgumentTypeDefaultDescription
STRINGstringrequiredThe text to change.
INDEXindexrequiredThe place of TEXT: an integer, end, or end-N.
TEXTstringrequiredThe text to put in.

Returns

The new string.

Examples

% string insert abc 1 X
aXbc

% string insert abc end X
abcX

% string insert abc -5 X
Xabc

% string insert abc 10 X
abcX

Errors

% string insert abc x X
bad index "x": must be integer?[+-]integer? or end?[+-]integer?
-errorcode NONE

% string insert abc 1
wrong # args: should be "string insert string index insertString"
-errorcode TCL WRONGARGS

Facts

Capability
None.
Tcl release
Tcl 9.1 only.
Since
ztcl 1.0.0-beta.1

See also