Easy way to replace 0 with empty string?

Discussion in 'Perl Misc' started by Paul Tomlinson, Sep 25, 2003.

  1. Is there an easy one line way to replace a 0 with empty string?

    PT
     
    Paul Tomlinson, Sep 25, 2003
    #1
    1. Advertising

  2. In article <bkv54o$6g4oh$-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
     
    Andreas Kahari, Sep 25, 2003
    #2
    1. Advertising

  3. Andreas Kahari <> wrote:

    > In article <bkv54o$6g4oh$-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
     
    David K. Wall, Sep 25, 2003
    #3
  4. Paul Tomlinson

    Anno Siegel Guest

    Andreas Kahari <> wrote in comp.lang.perl.misc:
    > In article <bkv54o$6g4oh$-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
     
    Anno Siegel, Sep 25, 2003
    #4
  5. Paul Tomlinson <> wrote:
    > Is there an easy one line way to replace a 0 with empty string?


    $input =~ tr/0//d;

    --
    Steve
     
    Steve Grazzini, Sep 25, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Ahlers
    Replies:
    1
    Views:
    5,666
    Martin Honnen
    Jul 12, 2004
  2. Alun
    Replies:
    3
    Views:
    4,522
    Masudur
    Feb 18, 2008
  3. Tzury Bar Yochay
    Replies:
    1
    Views:
    406
    Gabriel Genellina
    Mar 24, 2008
  4. Savvoulidis Iordanis

    Empty gridview cells and checking for empty string

    Savvoulidis Iordanis, Sep 5, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    524
    Savvoulidis Iordanis
    Sep 5, 2008
  5. Replies:
    1
    Views:
    180
    Robert Klemme
    May 31, 2006
Loading...

Share This Page