[FR/EN] how to remove the characters '-'

Discussion in 'Perl Misc' started by Alextophi, Sep 19, 2005.

  1. Alextophi

    Alextophi Guest

    FR
    -------------------------------------------------------------------------
    bonjour

    comment supprimer les caracteres '-' devant et derrière cette chaine ?
    (pas ceux entre les mots)


    -Mon-Tue-Wed-Thu-Fri-Sat-Sun-


    Merci, christophe

    EN
    -------------------------------------------------------------------------
    hello

    how to remove the characters ' - ' in front of and behind this chains ?
    (not those between the words)

    -My-Kills-Wed-Thu-Fri-Sat-Sun-

    Thank you, Christophe
    Alextophi, Sep 19, 2005
    #1
    1. Advertising

  2. Alextophi

    Anno Siegel Guest

    Alextophi <> wrote in comp.lang.perl.misc:

    [french version snipped]

    > hello
    >
    > how to remove the characters ' - ' in front of and behind this chains ?

    ^^^^^
    Those characters don't appear in the string below.

    > (not those between the words)
    >
    > -My-Kills-Wed-Thu-Fri-Sat-Sun-


    What have you tried, and how did it fail?

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Sep 19, 2005
    #2
    1. Advertising

  3. Alextophi

    Sandman Guest

    In article <>,
    "Alextophi" <> wrote:

    > how to remove the characters ' - ' in front of and behind this chains ?
    > (not those between the words)
    >
    > -My-Kills-Wed-Thu-Fri-Sat-Sun-
    >
    > Thank you, Christophe


    I am assuming you mean how to remove the beginning and ending "-" character
    from the string. This is how:

    #!/usr/bin/perl
    use strict;
    use warnings;

    my $string = "-My-Kills-Wed-Thu-Fri-Sat-Sun-";
    $string=~s/^-(.*)-$/$1/;
    print $string;





    --
    Sandman[.net]
    Sandman, Sep 19, 2005
    #3
  4. Alextophi wrote:

    > how to remove the characters ' - ' in front of and behind this chains ?
    > (not those between the words)
    >
    > -My-Kills-Wed-Thu-Fri-Sat-Sun-
    >
    > Thank you, Christophe


    You would be better off using Ruby:

    s='-My-Kills-Wed-Thu-Fri-Sat-Sun-'
    s.gsub!( /^-|-$/, '' )
    puts s
    William James, Sep 20, 2005
    #4
    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. Simon-Pierre  Jarry
    Replies:
    2
    Views:
    2,354
    Henrik
    Aug 10, 2005
  2. Radovan Garabik

    Re: remove special characters from line

    Radovan Garabik, Jul 1, 2003, in forum: Python
    Replies:
    0
    Views:
    663
    Radovan Garabik
    Jul 1, 2003
  3. Egor Bolonev

    Re: remove special characters from line

    Egor Bolonev, Jul 1, 2003, in forum: Python
    Replies:
    2
    Views:
    535
    Chris Rennert
    Jul 1, 2003
  4. tshad
    Replies:
    6
    Views:
    21,438
    tshad
    Aug 8, 2006
  5. rvino
    Replies:
    0
    Views:
    4,637
    rvino
    Aug 14, 2007
Loading...

Share This Page