.NETGURU
replacing \n
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngregexp' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

dave wanta (VIP)
hi all,
Does anyone know the RegEx that would replace all instances of \n where there ISN'T a \r\n ?

Basically I want to make sure every \n is actually \r\n, but I need to make sure I don't end up with \r\n\n.

Make sense?

Thanks,
Dave
Reply to this message...
 
    
Wayne King (ASP.NET)
This is a multi-part message in MIME format.

--------------InterScan_NT_MIME_Boundary
Content-Type: multipart/alternative;
    boundary="----_=_NextPart_001_01C22EC8.3846B20A"

------_=_NextPart_001_01C22EC8.3846B20A
Content-Type: text/plain;
    charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Try this (using C# syntax):
sResult =3D Regex.Replace(sInput, @"(?<!\r)\n", @"\r\n");
=20
It seems like these would be less efficient:
sResult =3D Regex.Replace(sInput, @"([^\r]|^)\n", @"$1\r\n");
sResult =3D Regex.Replace(sInput, @"^\n|([^\r])\n", @"$1\r\n");
=20
=20
-Wayne=20
This posting is provided "AS IS" with no warranties, and confers no
rights.=20
=20
-----Original Message-----
From: dave wanta [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 17, 2002 4:00 PM
To: aspngregexp
Subject: [aspngregexp] replacing \n

hi all,
Does anyone know the RegEx that would replace all instances of \n where
there ISN'T a \r\n ?
=20
Basically I want to make sure every \n is actually \r\n, but I need to
make sure I don't end up with \r\n\n.
=20
Make sense?
=20
Thanks,
Dave

------_=_NextPart_001_01C22EC8.3846B20A
Content-Type: text/html;
    charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Bookman Old Style" color=3D#008000 size=3D2><SPAN=20
class=3D862533716-18072002>Try this (using C# =
syntax):</SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><SPAN=20
class=3D862533716-18072002>    sResult =3D =
Regex.Replace(sInput,=20
@"(?<!\r)\n", @"\r\n");</SPAN></FONT></DIV>
<DIV><FONT face=3D"Bookman Old Style" color=3D#008000 size=3D2><SPAN=20
class=3D862533716-18072002></SPAN></FONT> </DIV>
<DIV><FONT face=3D"Bookman Old Style" color=3D#008000 size=3D2><SPAN=20
class=3D862533716-18072002>It seems like these would be less=20
efficient:</SPAN></FONT></DIV>
<DIV><FONT face=3D"Bookman Old Style" color=3D#008000 size=3D2><SPAN=20
class=3D862533716-18072002>
<DIV><FONT face=3D"Courier New" color=3D#000000 size=3D2><SPAN=20
class=3D862533716-18072002>    sResult =3D =
Regex.Replace(sInput,=20
@"([^\r]|^)\n", @"$1\r\n");</SPAN></FONT></DIV></SPAN></FONT></DIV>
<DIV><FONT face=3D"Bookman Old Style" color=3D#008000 size=3D2>
<DIV><FONT face=3D"Courier New" color=3D#000000 size=3D2><SPAN=20
class=3D862533716-18072002>    sResult =3D =
Regex.Replace(sInput,=20
@"^\n|([^\r])\n", @"$1\r\n");</SPAN></FONT></DIV></FONT></DIV>
<DIV><SPAN lang=3Den-us><FONT face=3D"Courier New" =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN lang=3Den-us><FONT face=3D"Courier New" =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN lang=3Den-us><FONT face=3D"Courier New" =
size=3D2>-Wayne</FONT></SPAN>=20
<BR><SPAN lang=3Den-us><FONT face=3D"Courier New" size=3D2> This =
posting is=20
provided "AS IS" with no warranties, and confers no =
rights.</FONT></SPAN> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV></DIV>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr =
align=3Dleft><FONT face=3DTahoma=20
size=3D2>-----Original Message-----<BR><B>From:</B> dave wanta=20
[mailto:Click here to reveal e-mail address] <BR><B>Sent:</B> Wednesday, July 17, 2002 =
4:00=20
PM<BR><B>To:</B> aspngregexp<BR><B>Subject:</B> [aspngregexp] replacing=20
\n<BR><BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Does  anyone know the RegEx that =
would replace=20
all instances of \n where there ISN'T a \r\n ?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Basically I want to make sure =
every \n is=20
actually \r\n, but I need to make sure I don't end up with =
\r\n\n.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Make sense?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Dave</FONT></DIV></BODY></HTML>
=00
------_=_NextPart_001_01C22EC8.3846B20A--

--------------InterScan_NT_MIME_Boundary--

Reply to this message...
 
 
System.Text.RegularExpressions.Regex




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification