Main Index : Reference :

strins()


Description

Inserts a string at a given position in another.

Definition

[string] strins([string] str1,[string] str2,[int] pos)

Parameters

str1 is the original string.
str2 is the string that's inserted into str1.
pos is the insertion position within str1.

Return Value

strins() returns a copy of the string str1 where the string str2 has been inserted at the position pos. The parts of str1 that are covered by str2 are replaced. The length of the result is the same as the length of str1, so if str2 is too long it will be truncated. The insertion position, pos, can be negative.

Remember: The first character of a string is at position 0.

Example

// Outputs "abtestghij"

var str1 = "abcdefghij";
var str2 =   "test";
var pos = 2;

println(strins(str1,str2,pos));


// Outputs   "stingfghij"

var str1 =   "abcdefghij";
var str2 = "testing";
var pos = -2;

println(strins(str1,str2,pos));


// Outputs "abcdeftest"

var str1 = "abcdefghij";
var str2 =       "testing";
var pos = 6;

println(strins(str1,str2,pos));

See Also

[string], strmid(), stradd(), strset(), strstr(), strchr(), strcmp()