Parse boolean values in strings for use with Function.apply
Posted
by as3cmdline
on Stack Overflow
See other posts from Stack Overflow
or by as3cmdline
Published on 2010-03-13T09:50:16Z
Indexed on
2010/03/13
9:55 UTC
Read the original article
Hit count: 150
I'm using String.split
to parse a command line string into an array of strings. The result is then used to call a function using the Function.apply
API.
If apply(null, ["17"])
is called with this function:
static function test(foo:int):void
{
trace(foo, typeof(foo));
}
it works as expected (output: 17 number
).
However, calling apply(null, ["false"])
or apply(null, ["0"])
with this function:
static function test(foo:Boolean):void
{
trace(foo, typeof(foo));
}
does not work (expected output: false Boolean
; actual output: true Boolean
).
Is there a way to make it recognize "true"
and "false"
(or anything else) as Boolean values, just like it does with numerical strings? Ideally "true"
and "false"
should also remain valid string values.
© Stack Overflow or respective owner