Difference between revisions of "LlInsertString"

From Second Life Wiki
Jump to navigation Jump to search
Line 4: Line 4:
|p2_type=integer|p2_name=pos|p2_desc=position index for insert, first is 0
|p2_type=integer|p2_name=pos|p2_desc=position index for insert, first is 0
|p3_type=string|p3_name=src|p3_desc=source string to be inserted
|p3_type=string|p3_name=src|p3_desc=source string to be inserted
|func_footnote=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.
|func_footnote=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.
|func_desc
|func_desc
|return_text='''dst''' with '''src''' inserted starting at '''pos'''.
|return_text='''dst''' with '''src''' inserted starting at '''pos'''.
Line 11: Line 11:
|constants
|constants
|examples=
|examples=
<lsl>
<lsl>llInsertString("input", 2, "put out")// returns "input output"</lsl>
llInsertString("input", 2, "put out")// returns "input output"
|helpers=This function will allow you to use a negative number as the position:
</lsl>
<lsl>string insertString(string destination, integer position, string str) {
 
This function written by Strife Onizuka 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 < 0)
         position += llStringLength(destination);
         if ((position += llStringLength(destination)) < 0)
            position = 0;
     return llInsertString(destination, position, str);
     return llInsertString(destination, position, str);
}
}</lsl>
</lsl>
 
 
 
 
|helpers
|also_functions={{LSL DefineRow||[[llDeleteSubString]]}}
|also_functions={{LSL DefineRow||[[llDeleteSubString]]}}
{{LSL DefineRow||[[llGetSubString]]}}
{{LSL DefineRow||[[llGetSubString]]}}

Revision as of 05:29, 8 July 2008

Summary

Function: string llInsertString( string dst, integer pos, string src );

Returns a 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.
All Issues ~ Search JIRA for related Bugs

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

Search JIRA for related Issues

Signature

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