Difference between revisions of "LlInsertString"

From Second Life Wiki
Jump to: navigation, search
 
m (<lsl> tag to <source>)
 
(18 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{LSLFunctionAll|func_id=96|func_sleep=0.0|func_energy=10.0|func=llInsertString|return_type=string|p1_type=string|p1_name=dst|p2_type=integer|p2_name=position|p3_type=string|p3_name=src|func_footnote=inserts src into dst at position and returns the result|return_text|spec|caveats|examples|helpers|related|also|notes}}[[Category:LSL_Functions]][[Category:LSL_Stub]]
+
{{LSL_Function
 +
|inject-3={{LSL_Function/negative_index|false|pos}}
 +
|func_id=96|func_sleep=0.0|func_energy=10.0
 +
|func=llInsertString|return_type=string
 +
|p1_type=string|p1_name=dst|p1_desc=destination of insertion
 +
|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
 +
|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
 +
|Return_text={{LSLP|dst}} with {{LSLP|src}} inserted starting at {{LSLP|pos}}.
 +
|spec
 +
|caveats
 +
|constants
 +
|examples=
 +
<source lang="lsl2">llInsertString("input", 2, "put out")// returns "input output"</source>
 +
|helpers=This function will allow you to use a negative number as the position:
 +
<source lang="lsl2">string insertString(string destination, integer position, string str) {
 +
    if (position < 0)
 +
        if ((position += llStringLength(destination)) < 0)
 +
            position = 0;
 +
    return llInsertString(destination, position, str);
 +
}</source>
 +
|also_functions={{LSL DefineRow||[[llDeleteSubString]]}}
 +
{{LSL DefineRow||[[llGetSubString]]}}
 +
|also_events
 +
|also_tests
 +
|also_articles={{LSL DefineRow||[[:Category:LSL Examples|Examples:]] [[Library_Combined_Library#str_replace|str_replace]]|Replace all instances of a string with another string in a target string}}
 +
{{LSL DefineRow||[[:Category:LSL Examples|Examples:]] [[SplitLine]]|Insert 'new line' escape codes at certain positions of a string}}
 +
|notes
 +
|helpers
 +
|cat1=String
 +
|cat2
 +
|cat3
 +
|cat4
 +
}}

Latest revision as of 10:30, 22 January 2015

Summary

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

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

Examples

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

Useful Snippets

This function will allow you to use a negative number as the position:

string insertString(string destination, integer position, string str) {
    if (position < 0)
        if ((position += llStringLength(destination)) < 0)
            position = 0;
    return llInsertString(destination, position, str);
}

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 );