What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Replace Colour Codes

Replace Colour Codes
Author: Message:
deAd
Scripting Contest Winner
*****

Avatar

Posts: 1060
Reputation: 28
– / Male / Flag
Joined: Jan 2006
RE: Replace Colour Codes
Replacing can also be done with a simple loop.

Here's a function I made that replaces the default String.replace function. I haven't tested it thoroughly, but I'm sure the bugs are nothing complicated ;)

To use it, use the normal String.replace function. However, there is an extra parameter. "Count" is an integer, it'll specify how many occurrences to replace in the string. If you leave it out, it will replace all of them.

code:
String.prototype.replace = function(term,replacement,count){
    var string = this;
    if(count == null){
        while(string.indexOf(term) > -1){
            string = string.slice(0,string.indexOf(term)) + replacement + string.slice(string.indexOf(term)+term.length,string.length);
        }
    } else if(typeof count == 'number'){
        for(var i = 0; i < count; i++){
            string = string.slice(0,string.indexOf(term)) + replacement + string.slice(string.indexOf(term)+term.length,string.length);
        }
    }
    return string;
}
09-07-2006 09:17 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Replace Colour Codes - by Spunky on 09-07-2006 at 08:20 PM
RE: Replace Colour Codes - by alexp2_ad on 09-07-2006 at 08:31 PM
RE: Replace Colour Codes - by Spunky on 09-07-2006 at 08:32 PM
RE: Replace Colour Codes - by KnRd_WC on 09-07-2006 at 09:15 PM
RE: Replace Colour Codes - by deAd on 09-07-2006 at 09:17 PM
RE: Replace Colour Codes - by Spunky on 09-07-2006 at 09:18 PM
RE: Replace Colour Codes - by Shondoit on 09-08-2006 at 03:42 PM
RE: Replace Colour Codes - by Matti on 09-08-2006 at 04:17 PM
RE: Replace Colour Codes - by Shondoit on 09-08-2006 at 04:21 PM
RE: Replace Colour Codes - by CookieRevised on 09-08-2006 at 04:35 PM
RE: Replace Colour Codes - by Shondoit on 09-08-2006 at 04:45 PM
RE: RE: Replace Colour Codes - by CookieRevised on 09-08-2006 at 04:51 PM
RE: Replace Colour Codes - by Shondoit on 09-08-2006 at 04:57 PM
RE: Replace Colour Codes - by CookieRevised on 09-08-2006 at 05:07 PM
RE: Replace Colour Codes - by Spunky on 09-08-2006 at 05:15 PM
RE: Replace Colour Codes - by Eljay on 09-08-2006 at 05:20 PM
RE: Replace Colour Codes - by Spunky on 09-08-2006 at 05:23 PM
RE: Replace Colour Codes - by CookieRevised on 09-08-2006 at 05:24 PM
RE: Replace Colour Codes - by Spunky on 09-08-2006 at 05:28 PM
RE: Replace Colour Codes - by Shondoit on 09-08-2006 at 10:40 PM
RE: Replace Colour Codes - by Spunky on 09-08-2006 at 10:43 PM
RE: Replace Colour Codes - by Shondoit on 09-08-2006 at 10:49 PM
RE: Replace Colour Codes - by Spunky on 09-08-2006 at 10:51 PM
RE: Replace Colour Codes - by Shondoit on 09-08-2006 at 10:53 PM
RE: RE: Replace Colour Codes - by CookieRevised on 09-09-2006 at 02:08 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On