Hi,

I'm looking for the asp equivalent of PHP's sprintf/printf
function...In PHP you can do this:

$format = "There are %d monkeys in the %s";
printf($format,$num,$location);

This might output, "There are 5 monkeys in the tree".

You can also specify the order of the placeholders and repeat the
placeholders without adding more arguments in the code. Argument
swapping:

$format = "The %2\$s contains %1\$d monkeys. That's a nice %2\$s full
of %1\$d monkeys.";
printf($format, $num, $location);

Output, "The tree contains 5 monkeys. That's a nice tree full of 5
monkeys."

Any suggestions to acoomplish something similar with VBScript?

Thanks

Re: sprintf for VBScript? by Aaron

Aaron
Wed Aug 11 13:27:12 CDT 2004

Yes, write your own function that replaces tokens (I don't believe VBScript
has anything built in that will magically do this for you).

<%
function printf(str, t1, t2)
printf = replace(str, "%t1", t1)
printf = replace(printf, "%t2", t2)
end function

format = "The %t2 contains %t1 monkeys. " & _
"That's a nice %t2 full of %t1 monkeys."
num = 5
location = "tree"
response.write printf(format, num, location)
%>


--
http://www.aspfaq.com/
(Reverse address to reply.)




"Justin" <ng@NO_SPAMmaritimeNO_SPAMsource.ca> wrote in message
news:4lokh05qb3kj689e3sm4h36h0nlrsft7c7@4ax.com...
> Hi,
>
> I'm looking for the asp equivalent of PHP's sprintf/printf
> function...In PHP you can do this:
>
> $format = "There are %d monkeys in the %s";
> printf($format,$num,$location);
>
> This might output, "There are 5 monkeys in the tree".
>
> You can also specify the order of the placeholders and repeat the
> placeholders without adding more arguments in the code. Argument
> swapping:
>
> $format = "The %2\$s contains %1\$d monkeys. That's a nice %2\$s full
> of %1\$d monkeys.";
> printf($format, $num, $location);
>
> Output, "The tree contains 5 monkeys. That's a nice tree full of 5
> monkeys."
>
> Any suggestions to acoomplish something similar with VBScript?
>
> Thanks