Skip to content
lsl.devlsl.devLSL Dev

llReplaceSubString

function
Function syntax
string llReplaceSubString(
  1. string src,// Original source string to search.
  2. string pattern,// Substring pattern to find and replace.
  3. string replacement_pattern,// New substring that replaces the pattern.
  4. integer count// Maximum number of replacements to make (0 for all, positive for left-to-right, negative for right-to-left).
);
Returns
string
Energy
10

If count = 0, all matching substrings are replaced. If count > 0, substrings are replaced starting from the left/beginning of src. If count < 0, substrings are replaced starting from the right/end of src.

Returns a string that is the result of replacing the first count matching instances pattern in src with replacement_pattern.

How to use
string result = llReplaceSubString("", "", "", 0);
Example 1
default
{
state_entry()
{
string ex = "red foxes, red hens, red turnips";
// Replace first 2 matches, starting from the left side
ex = llReplaceSubString(ex, "red", "blue", 2);
llSay(0, ex); // Should say "blue foxes, blue hens, red turnips"
}
}
Example 2
default
{
state_entry()
{
string ex = "red foxes, red hens, red turnips";
// Replace first match, starting from the right side
ex = llReplaceSubString(ex, "red", "green", -1);
llSay(0, ex); // Should say "red foxes, red hens, green turnips"
}
}
Example 3
default
{
state_entry()
{
string ex = "red foxes, red hens, red turnips";
// Replace all matches
ex = llReplaceSubString(ex, "red", "yellow", 0);
llSay(0, ex); // Should say "yellow foxes, yellow hens, yellow turnips"
}
}
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from LlReplaceSubString, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.