开发者

How can I check that a string contains a certion word actionscript? [closed]

开发者 https://www.devze.com 2022-12-29 02:09 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplet开发者_如何学Ce, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplet开发者_如何学Ce, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

How can I check that a string contains a certion word actionscript?


The indexOf method


If you want to check for the existence of a word in strict sense (as a whole word, not part of another word), you can use regular expressions. For example, the string "hat" is contained in the string "I like that movie" as a substring but not as whole word. Use the String::match(pattern:*) method to search for regular expressions in a string.

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号