Regular Expression Translate

A

Amy L

It looks as if there is no equivalent .Net regular expression method that is
comparable to tr/// (Translate) in Perl.

I was looking to squash a specific duplicate character in a string.

In Perl its pretty trivial.

$myString =~ tr/././s;

This will essentially remove duplicate "." periods in a string. Doesn't
matter where they the period is or how many there are.

Is their a .Net equivalent to Perl's translate?

Amy.
 
M

Michael Bray

It looks as if there is no equivalent .Net regular expression method
that is comparable to tr/// (Translate) in Perl.

I was looking to squash a specific duplicate character in a string.

In Perl its pretty trivial.

$myString =~ tr/././s;

This will essentially remove duplicate "." periods in a string.
Doesn't matter where they the period is or how many there are.

Is their a .Net equivalent to Perl's translate?

Regex.Replace(...);

for your specific case, try:

Regex.Replace(s, @"\.+", ".");

-mdb
 
F

Fabio Z

Amy L said:
I was looking to squash a specific duplicate character in a string.

In Perl its pretty trivial.

$myString =~ tr/././s;

This will essentially remove duplicate "." periods in a string. Doesn't
matter where they the period is or how many there are.

Is their a .Net equivalent to Perl's translate?

myString = myString.Replace("..", "")
 

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

Top