473,396 Members | 1,779 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,396 software developers and data experts.

Literal string problem

Hi.

I am trying to read a simle text file into a string variable, alter the text
using string.Replace(), then use the resulting text as the body for an
email.

This works fine up until the second step. When I read the text in from the
file, all the line breaks get replaced with '\n\r' characters. This would
be OK if, when I used the text as the email body, the converted back to
newlines, but this does not happen, so my email is on one long line filled
with \n's and \r's.

How do I "unescape" these characters to be actual newlines in my email?

Thanks in advance for your help,

Mike
Nov 16 '05 #1
6 1638

"Mike" <no***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi.

I am trying to read a simle text file into a string variable, alter the
text using string.Replace(), then use the resulting text as the body for
an email.

This works fine up until the second step. When I read the text in from
the file, all the line breaks get replaced with '\n\r' characters. This
would be OK if, when I used the text as the email body, the converted back
to newlines, but this does not happen, so my email is on one long line
filled with \n's and \r's.

How do I "unescape" these characters to be actual newlines in my email?

Thanks in advance for your help,


Just to clarify, after C# mangles the string, the email body looks like
this:

Fax \n\rNumber: 92630404\n\rThis email is a receipt of your recharge,
automatically sent to the email\r\naddress specified.\r\n\r\

I want it to look like this:

Fax
Number: 92630404
This email is a receipt of your recharge, automatically sent to the email
address specified.

It's driving me crazy. How do I do this?

Mike
Nov 16 '05 #2
Hi Mike,

Could you provide a small but complete sample demonstrating your problem?
Do you manually add the breaks? They should be \r\n not \n\r

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
"Mike" <no***@hotmail.com> wrote in
news:%2****************@TK2MSFTNGP15.phx.gbl...

"Mike" <no***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi.

I am trying to read a simle text file into a string variable, alter the
text using string.Replace(), then use the resulting text as the body for
an email.

This works fine up until the second step. When I read the text in from
the file, all the line breaks get replaced with '\n\r' characters. This
would be OK if, when I used the text as the email body, the converted
back to newlines, but this does not happen, so my email is on one long
line filled with \n's and \r's.

How do I "unescape" these characters to be actual newlines in my email?

Thanks in advance for your help,


Just to clarify, after C# mangles the string, the email body looks like
this:

Fax \n\rNumber: 92630404\n\rThis email is a receipt of your recharge,
automatically sent to the email\r\naddress specified.\r\n\r\

I want it to look like this:

Fax
Number: 92630404
This email is a receipt of your recharge, automatically sent to the email
address specified.

It's driving me crazy. How do I do this?


I suspect you look at that variable in the debugger?
C# usually doesn't "mangle" strings; However, the debugger (for several good
reasons) displays control-characters in a human-readable form. You could use
Console.WriteLine or Debug.WriteLine to check.

Since I don't know of any method that would replace control characters with
their proper escape codes, I assume that's what happening. If not, please
post a sample.

Niki
Nov 16 '05 #4
Mike,

Could you post the code which you are using to generate this output? I
assume you are not using an @ quoted string literal to insert these escapes?
(that symbol is used to prevent C# from processing the escape characters -
they are left in the string exactly as they are shown). If you are, simply
remove the @ from before the first quote.

Chris.

"Mike" wrote:

"Mike" <no***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi.

I am trying to read a simle text file into a string variable, alter the
text using string.Replace(), then use the resulting text as the body for
an email.

This works fine up until the second step. When I read the text in from
the file, all the line breaks get replaced with '\n\r' characters. This
would be OK if, when I used the text as the email body, the converted back
to newlines, but this does not happen, so my email is on one long line
filled with \n's and \r's.

How do I "unescape" these characters to be actual newlines in my email?

Thanks in advance for your help,


Just to clarify, after C# mangles the string, the email body looks like
this:

Fax \n\rNumber: 92630404\n\rThis email is a receipt of your recharge,
automatically sent to the email\r\naddress specified.\r\n\r\

I want it to look like this:

Fax
Number: 92630404
This email is a receipt of your recharge, automatically sent to the email
address specified.

It's driving me crazy. How do I do this?

Mike

Nov 16 '05 #5
Mike <no***@hotmail.com> wrote:
Just to clarify, after C# mangles the string, the email body looks like
this:

Fax \n\rNumber: 92630404\n\rThis email is a receipt of your recharge,
automatically sent to the email\r\naddress specified.\r\n\r\


How are you viewing these strings? My guess is that you're seeing them
in the debugger, in which case no mangling has occurred at all - print
the string out to a console and you'll see it as you want to.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Hi Mike,

You could just do this, assuming the text is in a variable called myText :

myText = myText.Replace("\n\r",Environement.NewLine);

HTH,

Michel

"Mike" <no***@hotmail.com> wrote in message news:<#D**************@TK2MSFTNGP15.phx.gbl>...
"Mike" <no***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi.

I am trying to read a simle text file into a string variable, alter the
text using string.Replace(), then use the resulting text as the body for
an email.

This works fine up until the second step. When I read the text in from
the file, all the line breaks get replaced with '\n\r' characters. This
would be OK if, when I used the text as the email body, the converted back
to newlines, but this does not happen, so my email is on one long line
filled with \n's and \r's.

How do I "unescape" these characters to be actual newlines in my email?

Thanks in advance for your help,


Just to clarify, after C# mangles the string, the email body looks like
this:

Fax \n\rNumber: 92630404\n\rThis email is a receipt of your recharge,
automatically sent to the email\r\naddress specified.\r\n\r\

I want it to look like this:

Fax
Number: 92630404
This email is a receipt of your recharge, automatically sent to the email
address specified.

It's driving me crazy. How do I do this?

Mike

Nov 16 '05 #7

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

Similar topics

9
by: Steven T. Hatton | last post by:
This is from the draft of the previous version of the Standard: http://www.kuzbass.ru:8086/docs/isocpp/expr.html 2- A literal is a primary expression. Its type depends on its form...
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
14
by: Joe | last post by:
Hello All: I am trying to dynamically populate a web page with literal content and controls (textboxes and checkboxes (and eventually two buttons - the buttons do not appear in the code yet). I...
5
by: Mark A. Sam | last post by:
Hello, I am trying to use a literal control to past test onto a page from several buttons, so that each button displays something different. The problem I am encountering is that the text wraps...
0
by: karazy | last post by:
I have been reading all the forums and understand whats going wrong but am not sure how to fix it. I have written a basic doc/literal web service. But when it is called by a .net client it will...
9
by: subramanian100in | last post by:
Suppose we have char *a = "test message" ; Consider the comparison if (a == "string") ..... Here "string" is an array of characters. So shouldn't the compiler
5
by: polas | last post by:
Good morning, I have a quick question to clear up some confusion in my mind. I understand that using a string literal in a declaration such as char *p = "string literal" declares a pointer to...
1
by: Hetal | last post by:
Hi, I have been working on creating a dynamic table with controls on a ASP.NET webpage and i have been using literal controls to do that. The issue that i am facing is, when i have the Start and...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.