aneuryzm
aneuryzm

Reputation: 64854

FLEX: how can I cut the strings longer than N characters

what's the easiest way to cut string in Flex ? I mean, I have a sequence of urls, I want them at most 60 characters length. If they are longer they should be cut and "..." should be added at the end.

<mx:LinkButton label="{bookmarksRepeater.currentItem.name}" click="navigateToURL(new URLRequest(event.currentTarget.label.toString()))" />

thanks

Upvotes: 0

Views: 577

Answers (2)

lunixbochs
lunixbochs

Reputation: 22415

if you can run full flex code in the label="" section, perhaps set the label to this: it's a conditional statement: if the name length is less than or equal to 60, just use the name, otherwise use the first 57 characters of the name and '...'

bookmarksRepeater.currentItem.name.length <= 60 ? bookmarksRepeater.currentItem.name : bookmarksRepeater.currentItem.name.substr(0, 57) + '...'

Upvotes: 1

thelost
thelost

Reputation: 6694

substr(startIndex:Number = 0, len:Number = 0x7fffffff):String Returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len.

from HERE

Upvotes: 1

Related Questions