llInsertString
string llInsertString(string TargetVariable, integer Position, string SourceVariable)Inserts SourceVariable into TargetVariable at Position, and returns the result.
Inserts SourceVariable into TargetVariable at Position and returns the result. Note this does not alter TargetVariable.
Parameters
-
TargetVariable(string) -
Position(integer) -
SourceVariable(string)
llInsertString("input", 2, "put out") // returns "input output"Helpers
Section titled “Helpers”insertString with Negative Index Support
Section titled “insertString with Negative Index Support”Unlike llGetSubString and llDeleteSubString, llInsertString does not accept negative indices for position counting. Use this helper function to add that capability:
string insertString(string destination, integer position, string str) { if (position < 0) if ((position += llStringLength(destination)) < 0) position = 0; return llInsertString(destination, position, str);}This wrapper allows you to use negative numbers as the position parameter, where -1 refers to the last position in the string.
- Unlike
llGetSubStringandllDeleteSubString,llInsertStringdoes not accept negative indices for position counting - The position parameter is zero-indexed (first character is at position 0)
- Does not modify the original strings; returns a new string with the insertion
See Also
Section titled “See Also”- llDeleteSubString
- llGetSubString
- llReplaceSubString
str_replace(Library) - Replace all instances of a string with another string
Related Examples
Section titled “Related Examples”- SplitLine - Insert newline escape codes at certain positions of a string