RobVious RobVious - 2 months ago 20
C# Question

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.

Answer

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

Comments