llReplaceSubString
function
Function syntax
string llReplaceSubString(string src,// Original source string to search.string pattern,// Substring pattern to find and replace.string replacement_pattern,// New substring that replaces the pattern.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.
string result = llReplaceSubString("", "", "", 0);Examples
Section titled “Examples”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" }}See also
Section titled “See also”Functions
Section titled “Functions”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.