Re: trying to shorten long string

2015-03-09 Thread Dean Lawrence
Well, the reason for the alternative approach is that he didn't specify why he wanted to truncate the description. Typically, this is due to layout and not necessarily content. Also, counting words breaks down as soon as you introduce html into the mix, because it is very easy to lop off closing t

Re: trying to shorten long string

2015-03-09 Thread Michael Grant
I think the point is that he's trying to truncate the text in a meaningful way, such as at the end of a sentence. One way around "4.5 houses" is to only use a period as a delimiter if it is followed by at least one space and an uppercase letter. It's not perfect of course, but it would eliminate m

Re: trying to shorten long string

2015-03-09 Thread Dean Lawrence
Another option would be to place the entire description in a div and then truncate it via css. http://www.w3schools.com/cssref/css3_pr_text-overflow.asp On Sat, Mar 7, 2015 at 1:31 AM, Mark Spence wrote: > > I have a long product description I am trying to truncate. I could just > truncate it

Re: trying to shorten long string

2015-03-09 Thread Bryan Stevenson
just keep in mind that periods exist in text for other reasons than ending sentences - this code will NOT always work as intended This will kill your desired end result "There are 4.5 houses finished." ;-) SorryI don't have a solution handy - just spotted a potential issue Take care -Brya

Re: trying to shorten long string

2015-03-07 Thread Byron Mann
Might be something to test, but first look if there is no period on a string +200, I don't believe anything will return. Another method might be to use reMatch to break the string into an array of sentences. Then loop over the returned array, concatenating the string back together until length >

Re: trying to shorten long string

2015-03-07 Thread Captain Obvious
Variable I is undefined. This works, #variables.description# On Sat, Mar 7, 2015 at 1:31 AM, Mark Spence wrote: > > I have a long product description I am trying to truncate. I could just > truncate it, but I don't want to break off sen

trying to shorten long string

2015-03-06 Thread Mark Spence
I have a long product description I am trying to truncate. I could just truncate it, but I don't want to break off sentences. Here is the solution I came up with but it does not seem to have any effect. Any ideas? ~