Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trim multiple spaces in a string in BASH
11-21-2009, 06:24 AM (This post was last modified: 11-22-2009 02:21 AM by Back_track.)
Post: #1
Trim multiple spaces in a string in BASH
echo "Hello world Smile" | tr -s " "

result = Hello world Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
05-16-2010, 09:09 PM
Post: #2
RE: Trim multiple spaces in a string in BASH
I was looking through bash commands that codecaine posted and i came on to this one.
I though that it would be good to make it.
I know that Delphi has similar function that only trims spaces " ".
It has trim(), trimleft() and trimright() functions.
Here is the example :
Code:
var
string mystring;
begin
mystring = '  Text     ';
showmessage('[' + trimleft(mystring)  + ']');
showmessage('[' + trimright(mystring) + ']');
showmessage('[' + trim(mystring)      + ']');
end;
And the output should be :
Code:
[Text     ]
   [  Text]
   [Text]

"I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: