Regular Expression Translate

  • Thread starter Thread starter Amy L
  • Start date Start date
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.
 
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
 
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("..", "")
 
Back
Top