Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding a line break for Twilio SMS using C#?

I'm using WebApi 2.2 to ramp up on the Twilio API. I have the Twilio C# libraries installed.

I'm using a form to capture a string in my web app, and I send that down to webAPI. I'm wondering how I can leverage the C# libraries to send a message with line breaks.

The example code shows the following:

        var msg = twilio.SendMessage("+15084043345", "+15084043345", "Can you believe it's this easy to send an SMS?!");

However, I'm not sure how to include a line break in this message. Should I be inserting anything into this string clientside to represent a linebreak? Any guidance would be awesome.

like image 988
RobVious Avatar asked Oct 06 '14 02:10

RobVious


People also ask

How do I add a line break in SMS?

The escape character \n will result in a newline character (line break).

How do I add a new line in API?

Using a <br> tag will give you a new line.

How do I send a message to multiple numbers in Twilio?

Each new SMS message from Twilio must be sent with a separate REST API request. To initiate messages to a list of recipients, you must make a request for each number to which you would like to send a message. The best way to do this is to build an array of the recipients and iterate through each phone number.


2 Answers

Twilio Evangelist here.

This is actually super simple:

var msg = twilio.SendMessage("+15084043345", "+15084043345", "Hello.\nCan you believe it's this easy to send an SMS?!");

Will result in:

Hello. Can you believe it's this easy to send an SMS?!

Just like printing strings to the console, \n, \r\n, and \r can be used to insert a new line. I can't say definitively what is best to use across all handsets, but I have found \n to be pretty reliable. (I can say all three of these work on my iOS 8 device perfectly...)

like image 156
xmjw Avatar answered Oct 21 '22 00:10

xmjw


If you want to show new line in sms like

Account Name : suraj

Age : 24

then here is a code for asp.net VB

Dim value As String = "Account Name :" & "suraj" & vbCrLf & "Age :" & " 24"

it will show new line in SMS not in web page

like image 33
Suraj Avatar answered Oct 21 '22 01:10

Suraj