基于字符提取文本 - Flex

发布于 2024-08-24 01:34:27 字数 277 浏览 5 评论 0原文

我正在使用自动完成组件和 labelFunction,以便用户能够按其姓名或 ID 进行搜索。搜索完成后,我想将数据提取到查询中。

唯一的问题是我只需要查询的名称或 id,而不是两者,所以我想只从 id 变量中提取...

当前如果用户输入 - Joe 或如果他们输入 - 13

两者都会返回Joe - 13 通过自动完成组件的结果。

我正在使用破折号 - 直观地分隔结果。所以我想知道是否有一种方法可以从文本字段中提取文本到某个字符(在本例中为破折号)。

谢谢

I'm using an auto complete component and a labelFunction so that user have the ability to search by their name or id. Once the search is completed I'd like to extract the data to a query.

The only problem is that I only need the name or id for the query not both, so I'd like to pull from just the id variable...

Currently if the user types - Joe or if they type - 13

Both would return a result of Joe - 13 via the auto complete component.

I'm using a dash - To separate the results visually. So I'd like to know if theres a way to extract text from a text field up to a certain character in this case a dash.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城缀染半城烟沙 2024-08-31 01:34:27

这有点矫枉过正,但只是为了让你思考:

private function extractText(inputText:String) : String {
  var retVal:String = ""
  var ary:Array = inputText.split('-');
  retVal = String(ary[0]); // use index 1 if you want the second half
  // you may want to trim white-space from this
  return retVal;
}

This is overkill, but just to get you thinking:

private function extractText(inputText:String) : String {
  var retVal:String = ""
  var ary:Array = inputText.split('-');
  retVal = String(ary[0]); // use index 1 if you want the second half
  // you may want to trim white-space from this
  return retVal;
}
猫性小仙女 2024-08-31 01:34:27

尝试:

string.slice(0,string.indexOf("-"));

应该到达破折号

string.slice(string.indexOf("-"),string.length);

应该从破折号获得。
您可能需要添加或减去这些数字来对其进行微调

Try:

string.slice(0,string.indexOf("-"));

should get to the dash

string.slice(string.indexOf("-"),string.length);

should get from the dash.
you will probably want to add or subtract from those numbers to fine tune it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文