Difference between revisions of "LlInsertString"

From Second Life Wiki
Jump to navigation Jump to search
m
m (wrong injection point)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/negative_index|false|pos}}
|inject-3={{LSL_Function/negative_index|false|pos}}
|func_id=96|func_sleep=0.0|func_energy=10.0
|func_id=96|func_sleep=0.0|func_energy=10.0
|func=llInsertString|return_type=string
|func=llInsertString|return_type=string

Revision as of 22:46, 15 January 2014

Summary

Function: string llInsertString( string dst, integer pos, string src );
0.0 Forced Delay
10.0 Energy

Returns the string dst with src inserted starting at pos.

• string dst destination of insertion
• integer pos position index for insert, first is 0
• string src source string to be inserted

pos does not support negative indexes. i.e. unlike other somewhat similar string functions such as llGetSubString and llDeleteSubString, you cannot use -1 for the counting with this function. You may use instead the function provided a bit further below.

Caveats

  • If pos is out of bounds the script continues to execute without an error message.

Examples

<lsl>llInsertString("input", 2, "put out")// returns "input output"</lsl>

Useful Snippets

This function will allow you to use a negative number as the position: <lsl>string insertString(string destination, integer position, string str) {

   if (position < 0)
       if ((position += llStringLength(destination)) < 0)
           position = 0;
   return llInsertString(destination, position, str);

}</lsl>

See Also

Functions

•  llDeleteSubString
•  llGetSubString

Articles

•  Examples: str_replace Replace all instances of a string with another string in a target string
•  Examples: SplitLine Insert 'new line' escape codes at certain positions of a string

Deep Notes

Signature

function string llInsertString( string dst, integer pos, string src );