473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Regex.Replace with a CRLF. Help?

Jon
Hi...

I'm getting stumped over the something that MUST be simple...basically, I'm
trying to replace the characters 0D0A with a crlf, using Regex.Replace().

The problem is, the replaced string includes the literal \r and \n, not a
CRLF. I've also tried Enviroment.Newline, but this gives the same effect.

Can anyone help me with this?

Thanks

Jon
Nov 17 '05 #1
3 10644
Remember that CRLF stand for Carriage Return and Line Feed.

Consulting trusty www.asciitable.com, we see that an ascii character code of
0x0A is a new line, while 0x0D is a carriage return, just as \n and \r are
the escape characters for a new line and carriage return respectively.

If you run:

Regex.Replace("All spaces in this string will be replaced with a hard
return"," ","\r\n");

You will see all spaces replaced with \r\n in the debugger, but if you dump
them to a file or to a text output you will see the hard returns you desire.

I may be off on what I am saying as I don’t complete understand your problem.

Brendan
"Jon" wrote:
Hi...

I'm getting stumped over the something that MUST be simple...basically, I'm
trying to replace the characters 0D0A with a crlf, using Regex.Replace().

The problem is, the replaced string includes the literal \r and \n, not a
CRLF. I've also tried Enviroment.Newline, but this gives the same effect.

Can anyone help me with this?

Thanks

Jon

Nov 17 '05 #2
Try Regex.Replace("First Line0D0ASecond
Line","0D0A",System.Environment.NewLine);

Hope it helps,
Ludovic SOEUR.

"Jon" <Jo*@discussions.microsoft.com> a écrit dans le message de
news:0B**********************************@microsof t.com...
Hi...

I'm getting stumped over the something that MUST be simple...basically, I'm trying to replace the characters 0D0A with a crlf, using Regex.Replace().

The problem is, the replaced string includes the literal \r and \n, not a
CRLF. I've also tried Enviroment.Newline, but this gives the same effect.

Can anyone help me with this?

Thanks

Jon

Nov 17 '05 #3
In article <0B**********************************@microsoft.co m>, Jon wrote:
I'm getting stumped over the something that MUST be simple...basically, I'm
trying to replace the characters 0D0A with a crlf, using Regex.Replace().

The problem is, the replaced string includes the literal \r and \n, not a
CRLF. I've also tried Enviroment.Newline, but this gives the same effect.


The .NET implementation of regular expressions doesn't seem to recognize
character escapes in the replacement string. The description of replacement
patterns in the VS help doesn't include character escapes so it's probably the
way it was supposed to work.

When I ran into this (trying to let a user specify replacement characters in
hex), I ended up preprocessing the replacement pattern to change, for
instance, \x0d into a binary return character.

Mike

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DDK | last post by:
I am trying to figure out how to Replace tags such as ... with the correct HTML <b>...</b> tags in C#. The code below works however only if one set of tags are found, if you have more than two...
1
by: Brian Patterson | last post by:
I'm using code similar to the following to search a line of code. I want to replace what was found with a modified version of the text. My regex pattern is "ListView\w*". And the line of text...
1
by: GlennH | last post by:
I am having trouble removing a pipe character using Regex.Replace - see the 2 NUnit tests below: The first replace works fine and the second Replace does not work. I've tried escaping the pipe...
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
3
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
9
by: Whitless | last post by:
Okay I am ready to pull what little hair I have left out. I pass the function below my String to search, my find string (a regular expression) and my replace string (another regular expression)....
3
by: Roger | last post by:
I'm having a little trouble using the Regex.Replace method. I am trying to perform a search and replace based on string pattern. I've been successful in replacing string from it's starting...
4
by: Morgan Cheng | last post by:
In my case, I have to remove any line containing "0.000000" from input string. In below case, it takes about 100 ms for 2k size input string. Regex.Replace(inputString, ".*0\\.000000.*\n", ""); I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.