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

A

Alextophi

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
 
A

Anno Siegel

[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
 
S

Sandman

Alextophi said:
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;
 
W

William James

Alextophi said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top