开发者

Extract Text based on Character - Flex

开发者 https://www.devze.com 2022-12-22 10:04 出处:网络
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.

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 se开发者_Python百科parate 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


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;
}


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

0

精彩评论

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

关注公众号