Dale wrote:
> Hi,
> 
> I'm trying to remove multiple spaces from a string but can't seemed to
> get it to do what I want without creating a long subroutine.
> 
> I have a text file that contains various pieces of data that I want to
> import. However, there are gaps in between of various sizes.  I want
> to cut them down to 1 space only.
> 
> The only way I can see to do this is to create various substituted
> strings of various lengths to make sure I get them all :
> 
> $str =~ s/          / /i;
> $str =~ s/         / /i;
> $str =~ s/        / /i;
> $str =~ s/       / /i;
> $str =~ s/      / /i;
> $str =~ s/     / /i;
> $str =~ s/    / /i;
> $str =~ s/   / /i;
> $str =~ s/  / /i;
> 
        $str =~ s/\s+/ /g;
This will take one or more white space and replace all found with one space.  
If you only want a space then s/ +/ /g would  be what you want. white space 
would cover tabs and spaces.
Wags ;)
> Is there an easier way to do this as I could end up with 48 of these
> from 2 spaces to 50 spaces?
> 
> Cheers!
> --
> Dale



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to