Regular Expressions

  • Thread starter Thread starter Paul Cowan
  • Start date Start date
P

Paul Cowan

Hi all,

I am trying to remove all carriage returns from a long string.

I have the following code

//use a regular expression to remove all carriage returns
Regex regex = new Regex("\r");
regex.Replace(decodedString, "");

It is not working,

does anyone know why??

Thanks

Paul
 
Paul Cowan said:
I am trying to remove all carriage returns from a long string.

I have the following code

//use a regular expression to remove all carriage returns
Regex regex = new Regex("\r");
regex.Replace(decodedString, "");

It is not working,

does anyone know why??

I suspect it's going on a single-line basis, and thus getting confused.
Fortunately, you don't need a regular expression at all. Just use:

decodedString = decodedString.Replace ("\r", "");
 
Hi Paul,

It's been a while, but ...

|| Regex regex = new Regex("\r");
|| regex.Replace (decodedString, "");

regex.Replace() doesn't change the string passed in - it returns the
replacement string.

So you could have -

Regex regex = new Regex("\r");
nocrString = regex.Replace (decodedString, "");

When you say carriage returns, you do mean specifically "\r", and not
carriage return-line feed?

Regards,
Fergus
 
Back
Top