replace_str - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: replace_str (/showthread.php?tid=83564) replace_str by Zeelia on 05-06-2008 at 06:36 PM
Hi! quote: i want it to search for i.e afk in the whole message im sending, for example: /replaceM im going afk now, bye! i want it to search for 'afk' in the sentence and replace the word 'afk' with '<Away From Keyboard>' how can i do that? search for a word in a sentence and then replace it with another word? RE: replace_str by MeEtc on 05-06-2008 at 08:24 PM
This should work well for you: RE: replace_str by Zeelia on 05-06-2008 at 08:36 PM
Thanks! That did work very well indeed. RE: replace_str by roflmao456 on 05-06-2008 at 09:19 PM
code: read the JScript 5.6 documentation on arrays or you can go to W3Schools RE: replace_str by Zeelia on 05-06-2008 at 11:01 PM
Thank you very much RE: replace_str by CookieRevised on 05-07-2008 at 02:09 AM
quote:Although it works, such loop code isn't needed though. JScript already has a (very powerfull) Replace function. eg: Debug.Trace("ThA mAn hit thA ball with the bat".replace(/A/g, "e")); will output: "The men hit the ball with the bat" As with everything, forum search CookieRevised's reply to how do i replace this text? > see Part 3 CookieRevised's reply to [Question] Isn't string.replace supposed to replace all occurences ? CookieRevised's reply to [I help them] VB2JS PS: yes, you can also use arrays with some small coding (since the Replace function uses regular expressions and actually accepts a function reference as replacement text too). That is done several times already on the forums too (cba to search for it atm). nevertheless nice code find RE: replace_str by Zeelia on 05-07-2008 at 11:02 PM
Ok alright, thank you now that you show me this example, i see how it works and i think that this way is much more easier and takes less space on the script (since the "php function" takes like 3 kb, which isn't that much anyway, on the script). |