Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Easy way to replace 0 with empty string?

Reply
Thread Tools

Easy way to replace 0 with empty string?

 
 
Paul Tomlinson
Guest
Posts: n/a
 
      09-25-2003
Is there an easy one line way to replace a 0 with empty string?

PT


 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      09-25-2003
In article <bkv54o$6g4oh$(E-Mail Removed)-berlin.de>, Paul Tomlinson wrote:
> Is there an easy one line way to replace a 0 with empty string?


Do you need anything more sofisticated than "s/0//"?


$ perl -e '$a=10; $a =~ s/0//;print $a, "\n"'
1



--
Andreas Kähäri
 
Reply With Quote
 
 
 
 
David K. Wall
Guest
Posts: n/a
 
      09-25-2003
Andreas Kahari <(E-Mail Removed)> wrote:

> In article <bkv54o$6g4oh$(E-Mail Removed)-berlin.de>, Paul
> Tomlinson wrote:
>> Is there an easy one line way to replace a 0 with empty string?

>
> Do you need anything more sofisticated than "s/0//"?
>
>
> $ perl -e '$a=10; $a =~ s/0//;print $a, "\n"'
> 1


If it's just a single character I'd use 'tr/0//d'.

I'm not entirely sure what is meant by "empty string". It might
possibly mean replacing '0' with a space: 'tr/0/ /'.

--
David Wall
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      09-25-2003
Andreas Kahari <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> In article <bkv54o$6g4oh$(E-Mail Removed)-berlin.de>, Paul Tomlinson wrote:
> > Is there an easy one line way to replace a 0 with empty string?

>
> Do you need anything more sofisticated than "s/0//"?
>
>
> $ perl -e '$a=10; $a =~ s/0//;print $a, "\n"'
> 1


The OP has under-specified his problem. What he wants may also be the
common idiom "$x ||= ''". It replaces 0 (and undef) with an empty string.

Anno
 
Reply With Quote
 
Steve Grazzini
Guest
Posts: n/a
 
      09-25-2003
Paul Tomlinson <(E-Mail Removed)> wrote:
> Is there an easy one line way to replace a 0 with empty string?


$input =~ tr/0//d;

--
Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy way to replace all non-alpha numeric chars in a string? deja@homerlex.mailshell.com Ruby 1 05-31-2006 04:18 PM
Altova Mapforce - xml 2 xml map: empty elements output although input element is not empty Lukas XML 3 11-10-2005 02:25 PM
Easy way to output a default value if <xsl:value-of/> selection comes back empty? Michael Ahlers XML 1 07-12-2004 05:17 PM
Check if a directory is empty and empty it Marcia Hon C Programming 8 02-14-2004 03:53 AM
empty/non-empty element John XML 1 07-16-2003 10:23 AM



Advertisments