| Blockland Forums > Modification Help |
| How to filter and replace a chat segment |
| << < (3/5) > >> |
| Truce:
--- Quote from: lilboarder32 on November 29, 2010, 12:56:56 AM ---I don't believe striReplace exists. Only strReplace exists last time I checked. --- End quote --- + --- Quote from: Red_Guy on November 29, 2010, 01:11:57 AM ---try something like this: %search = "World"; %change = "Changed"; %pos = strpos(%chatMsg, %search); %newMessage = getSubstr(%chatMsg, 0, %pos) @ %change @ getSubstr(%chatMsg, %pos + strlen(%search), strlen(%chatMsg) ); --- End quote --- = --- Code: ---function striReplace(%source,%search,%replace) { if(%search !$= "") { %len = strLen(%search); while((%pos = striPos(%source,%search)) != -1) %source = getSubStr(%source,0,%pos) @ %replace @ getSubStr(%source,%pos + %len,strLen(%source)); } return %source; } --- End code --- |
| MegaScientifical:
--- Quote from: Truce on November 29, 2010, 12:22:35 PM ----snip- --- End quote --- Wait, what if you want to use it to change the case on words? Like, make "CAt" "Cat" ? Wouldn't that cause a doom loop? Ya, it'd complicate the code, but might be required... |
| Truce:
--- Quote from: MegaScientifical on November 29, 2010, 12:28:00 PM ---Wait, what if you want to use it to change the case on words? Like, make "CAt" "Cat" ? Wouldn't that cause a doom loop? Ya, it'd complicate the code, but might be required... --- End quote --- Ok, fine. Complication for case changing go: --- Code: ---function striReplace(%source,%search,%replace) { if(%search $= "") return %source; %lena = strLen(%source); %lenb = strLen(%search); for(%i = 0; %i < %lena; %i++) { %part = getSubStr(%source,%i,%lenb); if(%part !$= %search) { %clean = %clean @ getSubStr(%source,%i,1); continue; } %clean = %clean @ %replace; %i += %lenb - 1; } return %clean; } --- End code --- |
| MegaScientifical:
--- Quote from: Truce on November 29, 2010, 12:43:24 PM ---Ok, fine. Complication for case changing go: --- Code: ---function striReplace(%source,%search,%replace) { if(%search $= "") return %source; %lena = strLen(%source); %lenb = strLen(%search); for(%i = 0; %i < %lena; %i++) { %part = getSubStr(%source,%i,%lenb); if(%part !$= %search) { %clean = %clean @ getSubStr(%source,%i,1); continue; } %clean = %clean @ %replace; %i += %lenb - 1; } return %clean; } --- End code --- --- End quote --- You're some kind of God... I'm having a hard time reading that... %clean isn't setting right off... the.... I'm just going to try it out. But thanks for working with replaces involving changing a case of something. |
| Uristqwerty:
stripos. Case insensitive strpos. I just checked it in the console, and it exists. --- Code: ---function striReplace(%source, %search, %replace) { %len = strlen(%search); while((%i = stripos(%source, %search)) >= 0) { %source = getSubStr(%source, 0, %i) @ %replace @ getSubStr(%source, %i + %len, strlen(%source) - %i - %len); } return %source; } --- End code --- |
| Navigation |
| Message Index |
| Next page |
| Previous page |