34.204.169.76 |    

Navigation

Google Advertisement

Die Funktion trim() ist der gleichnamigen PHP Funktion nach empfunden. Sie entfernt Whitespaces am Anfang und Ende eines Strings. Die Funktion kann den String als Parameter $1 aber auch durch STDIN entgegen nehmen.

trim
  1. # ***************************************************************************
  2. # This function removes whitespace at the beginning and end of a string.
  3. #
  4. #  @param string $1 string (optional, can also handle STDIN)
  5. #  @return string
  6. #  @example:    echo " That is a sentinece " | trim
  7.  
  8. function trim() {
  9.  
  10. if [ -n "$1" ]; then
  11.         echo $1 | sed 's/^[[:space:]]*//g' | sed 's/[[:space:]]*$//g'
  12. else
  13.         cat - | sed 's/^[[:space:]]*//g' | sed 's/[[:space:]]*$//g'
  14. fi
  15.  
  16. }
Parsed in 0.005 seconds at 93.94 KB/s

Search
 
Full text search by name and content of a snippet.

User online
There are 2 users online.

Tags Cloud

Latest snippets
last day of last month
(Bash::Snippets)
crypt_apr1_md5
(PHP::Function)
crypt_apr1_md5
(Perl::Function)
transparent
(CSS)
rfc2822Toiso8601
(PHP::Function)
STDERR
(Bash::Function)
radius
(CSS)
shadow
(CSS)
rotate
(CSS)
create_function
(JavaScript::Snippets)