Tim Goodman
Tim Goodman

Reputation: 23976

How do I include a newline in a text message sent as email from an ASP.Net application?

I have an ASP.Net Application that sends text messages to mobile phones. It does this by sending an email. For instance, if your phone number is 555-555-5555 and your wireless carrier is Verizon, you can send an email to [email protected] and it will show up as a text message.

I want to be able to include a newline in the body of the message. How do I do this? Also please note that my ASP.Net program gets the message from a database (MS SQL Server) so what I really need to know is what characters to include in the message body when I store it in my database.

I already tried \n but it just showed up in the text message as \n

Upvotes: 8

Views: 6136

Answers (4)

ChessWhiz
ChessWhiz

Reputation: 4702

You need to use Environment.NewLine instead of \n

That has worked for me in the past, so it's the first thing I'd try if I were you.

Upvotes: 6

Forgotten Semicolon
Forgotten Semicolon

Reputation: 14100

I believe for SMS a linefeed is sufficient. From C#, you can use (char)10.

Upvotes: 2

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171401

I am not sure if you need just a line feed, or a carriage return/line feed, so try using CHAR, like this:

insert into Messages
(PhoneNo, Message)
values
('123-555-1234', 'line 1' + char(13) + char(10) + 'line 2')

Upvotes: 2

Russell Steen
Russell Steen

Reputation: 6612

Assuming you are building the bodies yourself prior to storage, the easiest way is to just use stringbuilder when building your strings and us .AppendLine(stuff); for each line

you can also use Environment.NewLine

Upvotes: 3

Related Questions