Re: strip first space
[EMAIL PROTECTED] [[EMAIL PROTECTED]] quoth: *> *>$string =~ s/^\s+//; Removes leading whitespaces *> *>$string =~ s/^\s+//g; /g (GLOBALLY) is redundant in the *>case of "leading whitespages" For a beginner, it's a not a critical detail. e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: strip first space
> If I have a string and the first character is a space, > may not always be a space. > Example: John > Tommy > Beth > > John and Beth have a space, Tommy does not. > How do I strip that. I do not want to use the global > command because a want the space between First > and Last name. Any suggestions? > > Susan I got this subroutine from a friend (who originally got it from the cookbook, I think). #this subroutine trims leading and trailing white space from a variable #it accepts either a variable or an array as its only argument sub Trim{ my @out = @_; for (@out){ s/^\s*(.*?)\s*$/$1/; } #end for return wantarray ? @out : $out[0]; } #end sub $name = "John Doe"; $name = Trim($name); print ("$name\n"); would return: John Doe So, in your case, the script would return: John Tommy Beth This routine strips the leading and trailing spaces, so it would allow you to maintain the space between the first and last name that you were worried about. Hope this helps... Jason CONFIDENTIALITY NOTICE: The information contained in this ELECTRONIC MAIL transmission is confidential. It may also be privileged work product or proprietary information. This information is intended for the exclusive use of the addressee(s). If you are not the intended recipient, you are hereby notified that any use, disclosure, dissemination, distribution [other than to the addressee(s)], copying or taking of any action because of this information is strictly prohibited.
Re: strip first space
$string =~ s/^\s+//; Removes leading whitespaces $string =~ s/^\s+//g; /g (GLOBALLY) is redundant in the case of "leading whitespages" See PERL Cookbook page 30 for the answer to your question. __ William Ampeh (x3939) Federal Reserve Board -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: strip first space
Tanton Gibbs [[EMAIL PROTECTED]] quoth: *> *>The regular expression *>s/^\s//; s/^\s+//g; would be even better as it would remove all whitspace at the beginning of a line and it would replace all matches to the pattern instead of just the first it finds. e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: strip first space
my @arr = (" This has a leading space", "This does not" ); foreach my $string (@arr ) { $string =~ s/^\s//; print $string, "\n"; } prints: This has a leading space This does not The regular expression s/^\s//; means s/ # substitute ^ # at the beginning of the string \s # one space character ( space, tab, or newline ) / # and replace it with / #nothing ; - Original Message - From: "Susan Aurand" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, March 01, 2002 1:08 PM Subject: strip first space > If I have a string and the first character is a space, > may not always be a space. > Example: John > Tommy > Beth > > John and Beth have a space, Tommy does not. > How do I strip that. I do not want to use the global > command because a want the space between First > and Last name. Any suggestions? > > Susan > Information Technology Center > 828-627-8314 > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]