38.107.191.113 |    

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.017 seconds at 27.92 KB/s

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

User online
There are 5 users online.

Tags Cloud

Latest snippets
urlencode
(Perl::Function)
gethostbyaddr
(Perl::Function)
create_function
(JavaScript::Snippets)
function_exists
(JavaScript::Snippets)
listing
(PHP::Function)
runPhpCode
(PHP::Function)
md5
(Bash::Function)
rtrim
(Bash::Function)
ltrim
(Bash::Function)
function_exists
(Bash::Function)