Cómo formatear una cadena para que se muestre en varias líneas

Here i have a message string that displays the content of an email. I would like the From, The subject and the body to all display on a new line.

Could someone please advise on how this is done. Below is what i'm trying but its all still on one line.

I thought enviroment.newline would work, i still think it will but maby im doing it wrong?

MessageString = "From: " + message.Headers.From.Address + Environment.NewLine + "Subject: " + message.Headers.Subject + Environment.NewLine + "Body: " + messagePart.BodyEncoding.GetString(messagePart.Body);

if you could also show me how to write code over multiple lines and still have it function that would be awesome too???????


preguntado el 03 de mayo de 12 a las 10:05

Is that not for Java? yup just tried it, i thinks that's for java :( but thanks for the try :) -

Where is that string presented? In log? On webpage? -

@Pomster "\n" is an escape character it is not language specific -

@Pomster Didn't Environment.NewLine work for you ? -

Enviroment.NewLine, "\n" and "\r\n" all have not worked and i have tryed them. The only one that worked was <br /> but that wont work outside of web i dont think. so i can move on :) but did not learn anything. But i do think enviroment.newline will work outside of web maby. -

2 Respuestas

If email is in html format then try <br />

contestado el 03 de mayo de 12 a las 10:05

Yes this works, but i can help but feel its not the right way to do things. What happens when i'm not displaying onto a webpage how do i new line a string? - pomster

As you did - Environment.NewLine. However, html is not sensitive for any newlines, whitespace, etc. and you have to use special tags to force newline. - empi

Thanks this was what i needed to know :D could you let me know how to code over multiple lines??? in VB its just _ and then start on the new line C# i'm unsure. I don't want a huge line of code neat code is the way:) - pomster

Just add enter. C# waits for semicolon. - empi

También puedes usar un Literal controlar con Mode establecido en PassThrough, y luego usa <br /> for a line break. Literals (and I guess also labels) HTML-encode their content, so a <br /> is not rendered as a line break by default.

However, be careful: You have to avoid XSS attacks on your own this way! The HttpUtility.HtmlEncode method is useful therefor.

contestado el 03 de mayo de 12 a las 10:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.