llReplaceSubString
string llReplaceSubString(string InitialString, string SubString, string NewSubString, integer Count)Searches InitialString and replaces instances of SubString with NewSubString. Zero Count means "replace all". Positive Count moves left to right. Negative moves right to left.
Parameters
-
InitialString(string) - The original string in which to hunt for substring matches.
-
SubString(string) - The original substring to find.
-
NewSubString(string) - The new substring used to replace.
-
Count(integer) - The max number of replacements to make. Zero Count means "replace all". Positive Count moves left to right. Negative moves right to left.
Replace first N matches from the left
Section titled “Replace first N matches from the left”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" }}Replace first match from the right
Section titled “Replace first match from the right”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" }}Replace all matches
Section titled “Replace all matches”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" }}- If
count= 0, all matching substrings are replaced - If
count> 0, substrings are replaced starting from the left/beginning of the source string - If
count< 0, substrings are replaced starting from the right/end of the source string