Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to apply Carriage return inside a string

Status
Not open for further replies.

ehx6

IS-IT--Management
May 20, 2004
150
0
0
US
Dim msgtext As String
msgtext = " hello " & Session("Investor") & _
" Username : " & vUserName & " " & _
" Password : " & vPassword & " " & _
"
Hi, the above is my code, in which once a user click on a button, it will send an email to the user. The email body recieved is all in one line, how can I control the carriage return in my code above, please advice and thanks
Ehx
 
In C#, it's Environment.NewLine
 
In VB, you can use the vbCrLf constant. But Environment.NewLine is better, as it comes from the .net framework that everyone uses, and not the VisualBasic compatability library.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi all,
I was not able to use Environment.Newline. On the other hand, vbCrLf did what I need to do; however, I would like to learn how to use Environment.Newline,
So if this is my text
dim mymessage as string
mymessage = " Dear User "
mymessage += " I am sending you this email "
mymessage += " to show you how to use a carraige return. "
mymessage += " Thanks for the folks at tek-tips.com "
mymessage += " Regards "
mymessage += " Ehx"

When I send this in the body, it become all in one line. so How can I implement (Environment.NewLine ) above
thanks for your help
Ehx

mymessage = " Dear User "

 
Just concatenate it to your string like you would any variable.
 
When building up a string like this, it's usually better to use a StringBuilder object (from the System.Text namespace). It performs better because there's less creation/destruction of objects going on.

C# code would be:
Code:
using System;
using System.Text;

//class defintion, blah blah blah

StringBuilder sb = new StringBuilder();

sb.Append(" Dear User ");
sb.Append(Environment.NewLine);
sb.Append("  I am sending you this email ");
sb.Append(Environment.NewLine);
sb.Append(" to show you how to use a carraige return. ");
sb.Append(Environment.NewLine);
sb.Append(" Thanks for the folks at tek-tips.com ");
sb.Append(Environment.NewLine);
sb.Append(" Regards ");
sb.Append(Environment.NewLine);
sb.Append(" Ehx");
sb.Append(Environment.NewLine);

return sb.ToString();
Chip H.

____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top