1.12 Removing trailing spaces

You probably know the problem. The user of your well-made program types his name and hits the spacebar before hitting the enter-key. There you go. His name will be stored in your datafile with a space and nobody will ever find it.

In 4tH there is a special word called '-TRAILING' that removes the extra spaces at the end with very little effort. Just paste it after 'COUNT'. Like we did in this example:

     32 string one                   \ define a string
     " Hans Bezemer    "             \ string with trailing spaces
     one copy                        \ now copy it to string one

     dup                             \ save the address

     ." ["                           \ print a bracket
     count type                      \ old method of printing
     ." ]" cr                        \ print bracket and newline

     ." ["                           \ print a bracket
     count -trailing type            \ new method of printing
     ." ]" cr                        \ print a bracket and newline

You will see that the string is printed twice. First with the trailing spaces, second without trailing spaces. And what about leading spaces? Patience, old chap. You've got a lot of ground to cover.