简体   繁体   English

使用C#为Twilio SMS编码换行符?

[英]Encoding a line break for Twilio SMS using C#?

I'm using WebApi 2.2 to ramp up on the Twilio API. 我正在使用WebApi 2.2来增加Twilio API。 I have the Twilio C# libraries installed. 我安装了Twilio C#库。

I'm using a form to capture a string in my web app, and I send that down to webAPI. 我正在使用表单在我的网络应用程序中捕获字符串,然后将其发送到webAPI。 I'm wondering how I can leverage the C# libraries to send a message with line breaks. 我想知道如何利用C#库发送带换行符的消息。

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? 我应该在此字符串clientide中插入任何内容以表示换行吗? Any guidance would be awesome. 任何指导都会很棒。

Twilio Evangelist here. Twilio Evangelist在这里。

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. 就像将字符串打印到控制台一样, \\n\\r\\n\\r \\r\\n可用于插入新行。 I can't say definitively what is best to use across all handsets, but I have found \\n to be pretty reliable. 我不能肯定地说所有手机最好用什么,但我发现\\n非常可靠。 (I can say all three of these work on my iOS 8 device perfectly...) (我可以说我的iOS 8设备上所有这三个工作完美......)

If you want to show new line in sms like 如果你想在短信中显示新行

Account Name : suraj 帐户名称:suraj

Age : 24 年龄:24岁

then here is a code for asp.net VB 那么这里是asp.net VB的代码

Dim value As String = "Account Name :" & "suraj" & vbCrLf & "Age :" & " 24" 昏暗值As String =“帐户名称:”&“suraj”&vbCrLf&“年龄:”和“24”

it will show new line in SMS not in web page 它将在短信中显示不在网页中的新行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM