Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.89/5 (2 votes)
See more:
HI guys,

I'm trying to insert newline in a string, but didn't get...

my code:

VB
string body =   "From :" + from + "\r"+
                            "To :" + to + "\r"+
                            "Sub :" + sub + "\r"+
                            ebody.Text;


even i tried \n , \r, and \n\r

Plz suggest me,

Thanks
Posted
Updated 28-May-22 15:08pm
Comments
Richard C Bishop 3-Feb-14 13:40pm    
<br />
Sergey Alexandrovich Kryukov 3-Feb-14 16:53pm    
5! :-)
—SA
Matt T Heffron 3-Feb-14 13:49pm    
What are you going to DO with this string?
If you are going to display it as part of an HTML page, then Richard (above) is correct.
If something else, then you need to determine what that something expects as a newline indicator.
Sergey Alexandrovich Kryukov 3-Feb-14 16:54pm    
Right, and new line is platform-dependent, but some details are ignored by some controls...
—SA

You are using here this string in asp script so you need to use html line break tag which is <br>
so instead of \r use br tag
 
Share this answer
 
v2
Comments
Peter Leow 3-Feb-14 23:38pm    
+5.
[no name] 5-Feb-14 1:17am    
thank you.
C#
string breakTag = "<br>";
           string body = "From :" + from + breakTag +
                           "To :" + to + breakTag +
                           "Sub :" + sub + breakTag +
                           ebody.Text;
 
Share this answer
 
Comments
Peter Leow 3-Feb-14 23:38pm    
+5.
Karthik_Mahalingam 3-Feb-14 23:47pm    
Thanks Peter:)
abdul subhan mohammed 4-Feb-14 2:21am    
5* thnx dude, got it!
Karthik_Mahalingam 4-Feb-14 4:00am    
welcome abdul subhan mohammed :)
C#
string strMailBody =string.empty;
strMailBody = "<table width="\"100%\"" cellpadding="\"0\"" class="\"viewtbl\"" cellspacing="\"0\"" border="\"0\""><tr><td>";
strMailBody += "<tr><td height="\"10px\""></td></tr>";
strMailBody += "<tr><td></td></tr>";
strMailBody += "<tr><td style="\"border-bottom:" 2px="" solid="" mode="hold" />strMailBody += "</tr></td></tr></table>";




do in this way using table..........
 
Share this answer
 
v3
Try

if the string is not intended for HTML Render ( Environment.NewLine is Windows equivalent for Line Break )

C#
string body =   "From :" + from + Environment.NewLine+
                            "To :" + to + Environment.NewLine+
                            "Sub :" + sub + Environment.NewLine+
                            ebody.Text;


Or else

C#
body = body.Replace(Environment.NewLine, "<br />")
which the solution says
 
Share this answer
 
Comments
abdul subhan mohammed 4-Feb-14 2:16am    
this one is not working...
RESULT:
From :software29@gmail.com To :subha29@gmail.com Sub :testing email #1: Focus on the user and all else will follow. Since the beginning, we’ve focused on providing the best user experience possible. Whether we’re designing a new Internet browser or a new tweak to the look of the homepage, we take great care to ensure that they will ultimately serve you, rather than our own internal goal or bottom line.
JoCodes 4-Feb-14 2:21am    
Is that a custom error? Environment.NewLine is a windows equivalent for line break , if in your case if trying for html rendering then use br . Solution was posted to to show the difference only.Anyways whats the error while you debug the code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900