[fpc-pascal] Trim repeated whitespace from a string

Michael Van Canneyt michael at freepascal.org
Sat May 27 11:57:37 CEST 2006



On Fri, 26 May 2006, Graeme Geldenhuys wrote:

> Hi,

Anybody know of a function that can remove (normalize) a string by
remove all beginning and ending whitespace as well as replace all
repeated spaces with a single space.  A bonus would be to remove tabs
and newlines chars as well, but that is not so important.

Example:
Before:   "  This is         what it    should        look like. "
After:       "This is what it should look like."

Use Trim from sysutils and then DelSpace1 from strutils.

http://www.freepascal.org/docs-html/rtl/strutils/delspace1.html

It might be a good idea to look at

http://www.freepascal.org/docs-html/rtl/strutils/index-5.html

Just so you know what is in store...

Michael.



More information about the fpc-pascal mailing list