Possible Duplicate:
How Can I Truncate A String In jQuery?
I’m pulling a feed from Facebook using jQuery and want to put a limit on the number of words/chars displayed in each message string.
i.e. If string contains more than 100 chars, it should stop at the nearest space and put ‘… read more ‘
How can I do this, simply?
You can test this function here jsfiddle
Or use this code to test it
var text = ‘The World Wide Web. When your average person on the street’;
console.log(truncateString(text, 52, ‘ ‘, ‘…’));