Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I currently use this function to tr 3

Status
Not open for further replies.

arcticpuppy

Technical User
Jan 14, 2003
8
US
I currently use this function to trim spaces from a string
function trim(str){
nsub1=sub("^[ ]*", "", str)
nsub2=sub("[ ]*$", "", str)
return str
}

I tried to use
nsub1=sub("^[ ]*", "\t", str)
nsub3=sub("[ ]*$", "\t", str)

to remove tabs and only was able to remove "tt" from my strings....does anyone have a asuggestion on how to remove leading tabs and following tabs from a string ?
 
sub("^[\t]*", "", str)
sub("[\t]*$", "", str) Gregor.Weertman@mailcity.com
 
Both the original post and answer are very helpful to me... but I am new and easily baffeled.
What is going on with the variables nsub1 and nsub2... I have tested the script and see it works perfectly but I do not see how return str is actually returning nsub1 or nsub2??

When you are as early on the learning curve as I am, every day brings new discoveries.
 

The sub function modifies the str argument directly and returns 1 is a substitution was made or 0 otherwise. The nsub1 and nsub2 variables are set to either 0 or 1 and then never used, at least not in the snippet presented.

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top