How to create strings in C# which contain "
开发者_StackOverflow中文版How can I create a string in C# which contains: AT+CGDCONT=1,"IP","internet"
string s = "AT+CGDCONT=1,\"IP\",\"internet\"";
try
string item1 = @"AT+CGDCONT=1,""IP"",""internet""";
or
string item2 = "AT+CGDCONT=1,\"IP\",\"internet\"";
You could use a string literal:
@"AT+CGDCONT=1,""IP"",""internet"""
Simply escape the double quotes using the escape character \
:
string foo = "AT+CGDCONT=1,\"IP\",\"internet\"";
This blog will give you a list of available escape sequences.
Use \
to escape characters in a C# string, so in your case:
var myString = "AT+CGDCONT=1,\"IP\",\"internet\"";
Just put a \ before the " like so:
string s = "AT+CGDCONT=1,\"IP\",\"internet\"";
string myString = "AT+CGDCONT=1,\"IP\",\"internet\""
Here is a list of all character escapes you can use.
精彩评论