BB___TRIM

=TRIM$= toc

Description
> Removes any white-space characters from the start and end of a string.


 * = **White Space** ||  ||= **ASCII Value** ||
 * Space ||  || CHR$(32) ||
 * Tab ||  || CHR$( 9) ||
 * Carriage Return + Line Feed ||  || CHR$(13)+CHR$(10) ||
 * Zero Character ||  || CHR$( 0) ||

Syntax

 * 1) trim$(//string//)

Hints
> Actually TRIM$ removes ALL characters with codes less then 33, not only "white-space characters".

> TRIM$ can be useful for removing unneeded spaces before writing the string to a disk file or adding it to a listbox or combobox. This improves the list appearance. It also assures that an item won't be skipped when selecting from a list by the first letter, for example.

Example
code format="vbnet" ' A simple example without TRIM$ name1$ = "Asparagus" name2$ = "  Carrots" print tab(7); name1$ print tab(7); name2$ print

' The same example with TRIM$ name1$ = "Asparagus" name2$ = "  Carrots" print tab(7); trim$(name1$) print tab(7); trim$(name2$) print

' This example will not print the second item from the list. print "List items by first letter:" print left$(name1$, 1) print left$(name2$, 1)

' This one prints the list correctly print "List items by first letter:" print left$(trim$(name1$), 1) print left$(trim$(name2$), 1) end code

code format="vbnet" ' In this example, counting the characters in the strings shows that ' the non-printing characters are there, even though they can't be seen.

' define carriage return + line feed CRLF$ = CHR$(13)+CHR$(10)

' define tab TAB$ = CHR$(9)

' concatenate text with white space Test1$ = CRLF$+"CRLF"+CRLF$ Test2$ = TAB$+"TAB"+TAB$

' print the length of the string with and without trimming print "Test1$       is "; LEN(Test1$); " characters long" print "TRIM$(Test1$) is "; LEN(TRIM$(Test1$)); " characters long" print "Test2$       is "; LEN(Test2$); " characters long" print "TRIM$(Test2$) is "; LEN(TRIM$(Test2$)); " characters long" End code

Useful Functions
code format="vbnet" Place a useful function using this command here code