Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How do I remove whitespace at the beginning or end of my string?

by vroom (His Eminence)
on Jan 21, 2000 at 00:45 UTC ( [id://2259]=note: print w/replies, xml ) Need Help??


in reply to How do I remove whitespace at the beginning or end of my string?

Use substitution along with the special characters ^ and $ which match the beginning and end of strings respectively along with \s which matches whitespace;
$string=~s/^\s+//; $string=~s/\s+$//;

Edited by davido: Removed useless use of /g modifier.
  • Comment on Re: How do I remove whitespace at the beginning or end of my string?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://2259]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found