Flex - 在 TextArea 中搜索字符串
我有一个允许用户输入的 TextArea。我还有 TextInput,用户可以在其中键入字符串,并且我希望能够在 TextArea 中搜索 TextInput 中的字符串。我以前从未做过这样的事情,搜索字符串,所以我不知道要使用哪些函数或如何进行。
有人可以解释一下如何做到这一点,或者甚至给出一个显示所涉及过程的小代码片段。谢谢。
编辑:
protected function searchBtn_clickHandler(event:MouseEvent):void
{
text = mainTextField.text;
search_Str = searchTxt.text;
var search_result:int = text.search(search_Str);
trace(search_result);
}
I have a TextArea that allows user input. I also have TextInput that the user can type a string into and I want to be able to search through the TextArea for the string in the TextInput. I've never done anything like this before, searching for strings, so I don't know which functions to use or how to go about it.
Could someone please explain how to do this, or even give a small code snippet showing the process involved. Thanks.
EDIT:
protected function searchBtn_clickHandler(event:MouseEvent):void
{
text = mainTextField.text;
search_Str = searchTxt.text;
var search_result:int = text.search(search_Str);
trace(search_result);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先从文本区域和输入字段中检索文本,例如:
然后我们将进行搜索:
现在
search_result
具有search_str
在 < code>text,如果未找到search_str
,则返回 -1。First retrieve the texts from the text area and input field, for example:
And then we'll do the seach:
Now
search_result
has the beginning index of thesearch_str
in thetext
, or -1 if thesearch_str
wasn't found.