Product Site

5.1.7.69. insert

Returns a copy of the receiver string with the string new, padded or truncated to length length, inserted after the nth character. The default value for n is 0, which means insertion at the beginning of the string. If specified, n and length must be positive whole numbers or zero. If n is greater than the length of the receiving string, the string new is padded at the beginning. The default value for length is the length of new. If length is less than the length of the string new, then insert truncates new to length length. The default pad character is a blank.
Example 5.106. String class — insert method
"abc"~insert("123")            -->    "123abc"
"abcdef"~insert(" ",3)         -->    "abc def"
"abc"~insert("123",5,6)        -->    "abc  123   "
"abc"~insert("123",5,6,"+")    -->    "abc++123+++"
"abc"~insert("123", ,5,"-")    -->    "123--abc"