blog

Quick Tip: Simpliest dictionary

Here is a short extract from a very simple dictionary engine I use on few of my latest projects. Even though it is based on single static method replace() , I always search and copy-paste the file from project to project, so I decided to publish it, maybe it can help someone else too …

package
{
    public class Dict
    {
        public static const LINK_IN_CLIPBOARD:String =
            "%1\nLink has been copied into the clipboard."

        public static const UPDATE_FLASH_PLAYER:String =
            "Please update your flashplayer.";

        public static const HELLO:String = "%1 %2";

        public static function replace(text:String, ... rest):String
        {
            var i:uint = 1;
            for each(var repl:String in rest)
                text = text.replace("%" + i++, repl);
            return text;
        }
    }
}

Usage:

trace(Dict.UPDATE_FLASH_PLAYER);
trace(Dict.replace(Dict.LINK_IN_CLIPBOARD, "http://somelink"));
trace(Dict.replace(Dict.HELLO, "Hello", "World"));

Have a nice one.