RobVious
RobVious

Reputation: 12915

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.

Upvotes: 8

Views: 2896

Answers (2)

Suraj
Suraj

Reputation: 51

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

Upvotes: 1

xmjw
xmjw

Reputation: 3434

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...)

Upvotes: 6

Related Questions