removing trailing spaces from string variables 
Author Message
 removing trailing spaces from string variables

What's the best way of removing trailing spaces from variables?
eg similar to VBs TRIM function.
Have I missed a string function somewhere ?

TIA
Mark



Sun, 18 May 2003 03:00:00 GMT  
 removing trailing spaces from string variables
Quote:

> What's the best way of removing trailing spaces from variables?
> eg similar to VBs TRIM function.
> Have I missed a string function somewhere ?

No, it just is trivial to implement "trim" functionality with sub().

Peter



Sun, 18 May 2003 03:00:00 GMT  
 removing trailing spaces from string variables

Quote:

> What's the best way of removing trailing spaces from variables?
> eg similar to VBs TRIM function.
> Have I missed a string function somewhere ?

 sub(/ +$/,"",variable)  # trailing

 sub(/^ +/,"",variable)  # leading

 gsub(/  +/," ",variable)  # pack internal spaces

--
  All true believers shall break their eggs at the convenient end.



Sun, 18 May 2003 03:00:00 GMT  
 removing trailing spaces from string variables

Quote:

>What's the best way of removing trailing spaces from variables?
>eg similar to VBs TRIM function.
>Have I missed a string function somewhere ?

The sub() function in nawk can do this:

{ sub(/[        ]+$/, ""); print }

        - Dan C.



Sun, 18 May 2003 03:00:00 GMT  
 removing trailing spaces from string variables
Ta for replies, Mark



Quote:
> What's the best way of removing trailing spaces from variables?
> eg similar to VBs TRIM function.
> Have I missed a string function somewhere ?

> TIA
> Mark



Mon, 19 May 2003 03:00:00 GMT  
 removing trailing spaces from string variables
On Wed, 29 Nov 2000 17:19:38 -0000, "DodoFrog"

Quote:

>What's the best way of removing trailing spaces from variables?
>eg similar to VBs TRIM function.
>Have I missed a string function somewhere ?

>TIA
>Mark

AWK applications often use spaces and tabs as field separators,
so that spaces do not occur in the field variables. AWKs that
allow regular expressions as field separators allow white space
to be trimmed as part of field splitting. AWK's g-/sub functions
allows you to trim spaces from variables by specifying the
appropriate arguments. AWK is not VB -- use it as a regular
expression processor, not just a fixed string processor, to get
the most benefit from the tool.

Thanks. Take care, Brian Inglis         Calgary, Alberta, Canada
--

                                use address above to reply



Thu, 22 May 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Removing trailing spaces from a field using awk

2. how to remove trailing blanks of a string?

3. strings and trailing spaces

4. removing spaces from string

5. Removing Extra Spaces From A String

6. help! remove embedded spaces from a string

7. How to remove spaces from a string ?

8. removing duplicate spaces from a string

9. how to remove spaces in a string

10. how to remove multiple space from string

11. Modifying existing script to remove trailing newlines

12. Remove trailing newlines from file

 

 
Powered by phpBB® Forum Software