a little bug fix
String.format("hello {{world}} {{escape}} {{won't escape}} {0} | need
to be 1 with brackets but gets value: {{1}}","value 1","value 2")
won't result the desired output.

i've wrote a function:
String.Format=function (s) {
        // © eLad
        var args=arguments;
        // the next rx matches every string like {#} but not with an escaped {
/ } ({{ / }}).
        // nonBracket is a character before a matched {#} which is a part of
the original string and can't be lost. since js doesn't support
negative lookbehinds this character must be saved and concatenated to
the result
        s=s.replace(/([^\{])\{([0-9]+)\}(?!\})/g,function
(whole,nonBracket,number) { return nonBracket+args[+number+1]; });
        // all escaped { / }
        s=s.replace(/\{\{/g,"{").replace(/\}\}/g,"}");
        return s;
}
alert(String.Format("arg 0: {0} | arg 1: {1} | escaped text:
{{escaped}} | escaped number: {{1}} | arg 2: {2}","value 0","value
1","value 2"));


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Ajax.NET Professional" group.

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]

For more options, visit this group at http://groups.google.com/group/ajaxpro

The latest downloads of Ajax.NET Professional can be found at 
http://www.ajaxpro.info
-~----------~----~----~----~------~----~------~--~---

Reply via email to