你如何将一个字符串转换在ActionScript布尔? [英] How do you convert a String into a Boolean in ActionScript?
本文介绍了你如何将一个字符串转换在ActionScript布尔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code:
var bool:String = "true";
没有的,如果块或switch语句,这可怎么转换成一个Boolean对象?
Without an if block or switch statement, how can this be converted into a Boolean object?
推荐答案
您可以使用:
var boolString:String = "true";
var boolValue:Boolean = boolString == "true"; // true
var boolString2:String = "false";
var boolValue2:Boolean = boolString2 == "true"; // false
修改
下面留言建议使用
var boolValue:Boolean = (boolString == "true") ? true : false;
这仅仅是复杂的code无缘无故作为评价发生在部分:
This is just complicating the code for no reason as the evaluation happens in the part:
(boolString == "true")
使用三元操作等效于:
Using the ternary operator is equivalent to:
var tempValue:Boolean = boolString == "true"; // returns true: this is what I suggested
var boolValue:Boolean = tempValue ? true : false; // this is redundant
这篇关于你如何将一个字符串转换在ActionScript布尔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文