0
如何检查一个字符串是否包含certion词actionscript?如何检查一个字符串是否包含验证词actionscript?
如何检查一个字符串是否包含certion词actionscript?如何检查一个字符串是否包含验证词actionscript?
的indexOf方法
如果您想为您在严格意义上的字的存在(作为一个整体的字,一个字不一部分),你可以使用正则表达式。例如,字符串"hat"
作为子字符串包含在字符串"I like that movie"
中,但不是整个字。使用String::match(pattern:*)
方法在字符串中搜索正则表达式。
var str:String = "I like that movie";
var t1:RegExp = /hat/; // `/` is the delimiter
var t2:String = /\bhat\b/; // `\b` denotes word boundary
if(str.match(t1) != null)
trace("hat is a substring");
if(str.match(t2) == null)
trace("but hat is not present as whole word");
只需要注意,RegExp :: test(string:String)将返回一个布尔值,从而删除与null的比较。例如:if(t1.test(str)){...} – 2012-08-24 21:37:28