Class: String
Description
This method returns an edited form of the String object in which the value of the replacement parameter is inserted into, or replaces part of the String object.
Syntax
StringObject.insert(String replacement,Number offset,
String padCharacter,Boolean displace)
Parameters
replacement |
The string to insert. |
offset |
The position within the String object where the insert starts (e.g. ,1 denotes the first character, etc.). The default offset is 1. |
padCharacter |
The character appended to the String object to ensure that its length is at least offset number of characters. If padCharacter contains more than one character, the first character is used. If not specified, a space is used. |
displace |
An option that indicates whether the inserted characters shift existing characters to the right.
|
Returns
A String.
When Became Available
v7.0
Example
type String STR = "be free, fly far away"
// All defaults: replace first n characters:
// "BE Free, fly far away"
type String INS1 = STR.insert("BE F")
// Insert in the middle:
// "be free, fly FAR away"
type String INS2 = STR.insert("FAR",14)
// Insert in the middle and displace;
// pad character is irrelevant when displace occurs
// "be free, fly VERY far away"
type String INS3 = STR.insert("VERY ",14,,1)
type String INS4 = STR.insert("VERY ",14,"#",1)
// Append and use alternate pad character;
// displace is irrelevant when padding is applied
// "be free, fly far away ***!"
type String INS5 = STR.insert("! ",25,"*",0)
type String INS6 = STR.insert("! ",25,"*",1)