Skip to content

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.
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"
}
}
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"
}
}
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