Blockland Forums > Modification Help
How to filter and replace a chat segment
<< < (4/5) > >>
MegaScientifical:

--- Quote from: Uristqwerty on November 29, 2010, 01:36:58 PM ---stripos. Case insensitive strpos. I just checked it in the console, and it exists.

-snip-

--- End quote ---

Dude, you just basically reposted Truce's first code. I asked him, and he made an even better version that accounts for making case changes to text with it. Why did you post that?
Uristqwerty:
I didn't notice that one.

In that case:


--- Code: ---function striReplace(%source, %search, %replace)
{
    if(strlen(%search) < 1)
      return;
    %len = strlen(%search);
    %i = 0;
    while((%i = stripos(%source, %search, %i)) >= 0)
    {
        %source = getSubStr(%source, 0, %i) @ %replace @ getSubStr(%source, %i + %len, strlen(%source) - %i - %len);
        %i += strlen(%replace);
    }
    return %source;
}

--- End code ---

Make use of that optional third argument!

(Edit: input check)
Miles Barlow:
Isn't there a function in torque to convert a string to lowercase?

Assigning the text to a variable, converting it to lowercase, then checking it for the word = possible solution?

I know this has been solved already, I just thought this was another way.
DrenDran:

--- Quote from: Miles Barlow on November 30, 2010, 03:34:40 AM ---Isn't there a function in torque to convert a string to lowercase?

Assigning the text to a variable, converting it to lowercase, then checking it for the word = possible solution?

I know this has been solved already, I just thought this was another way.

--- End quote ---
Yes there is, but there really isn't a way to get that case back after you've done your replacements.
So if this was filtering chat, then all chat would have to be lowercase if you did it that way.
Miles Barlow:

--- Quote from: DrenDran on November 30, 2010, 06:09:07 AM ---Yes there is, but there really isn't a way to get that case back after you've done your replacements.
So if this was filtering chat, then all chat would have to be lowercase if you did it that way.

--- End quote ---
Eh, didn't think about that  :cookieMonster:
Navigation
Message Index
Next page
Previous page

Go to full version