Reply to Re: Split string at word boundary

Your name:

Reply:


Posted by Stefan Rybacki on 10/17/69 11:19

ChrisJ wrote:
> I want to take a plain text string of arbitrary length and reduce its
> lenth to a set maximum. However I want the split to be at a word
> boundary (whitespace) not half way through a word.
>
> Is there an easy solution?

Well, define easy ;)

You could follow the following steps:

1. specify the max length
2. have a look at the textpositions: max,max+1
if one of this characters is a whitespace you just copy max
characters from the text (keep track of text length)
if not, you have to find the last whitespace in the text between
character 0 and character max

Well you don't really need to check the first condition, you just could
search for the first whitespace starting at the position max+1 as long
as max+1 is lower than the length of the text

Hope that helps

Regards
Stefan Rybacki



>
> ChrisJ

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация