Core Function StrInsert
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> StrInsert( <expression>, <index>, <expression2> ) </pre> === Description === Insert a string at a given index of another string and return the new string === Parameters ...") |
m (1 revision) |
||
(2 intermediate revisions by one user not shown) | |||
Line 37: | Line 37: | ||
$var = StrInsert($var, 3, "TEST"); | $var = StrInsert($var, 3, "TEST"); | ||
MsgBox($var); | MsgBox($var); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Can also be done like so | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | // Inserts CatDog into position 10 of the string | ||
+ | // since the string is only 5 chars long spaces | ||
+ | // will be automatically inserted to fill in the gaps | ||
+ | $Test = "Hello"; | ||
+ | $Test[10] = "CatDog"; | ||
+ | println("Value is: '$Test'"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:38, 14 June 2015
StrInsert( <expression>, <index>, <expression2> )
Contents |
Description
Insert a string at a given index of another string and return the new string
Parameters
expression
The source string.
index
Index position to place the second string within the first (First char is 0).
expression2
The string to place within the first.
Return Value
The new string.
Remarks
If index is below zero it will be set to 0.
If index is higher than destination length it will be appended to end of the destination string.
Example
$var = "I am a string"; $var = StrInsert($var, 3, "TEST"); MsgBox($var);
Can also be done like so
// Inserts CatDog into position 10 of the string // since the string is only 5 chars long spaces // will be automatically inserted to fill in the gaps $Test = "Hello"; $Test[10] = "CatDog"; println("Value is: '$Test'");