使用转义文字的字符串编码理解。 [英] String encoding understanding with escaped literals.

查看:124
本文介绍了使用转义文字的字符串编码理解。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我在尝试将字符串参数传递给辅助服务API调用时遇到问题。该方法无法识别我传递的字符串。我代码:



 StringBuilder builtString =  new  StringBuilder(); 
string startQuote = \ ; // 开始报价
string endQuote = \; // end quote
string nextEntry = \\\\ n; // 新行下一个条目
string 逗号= ;
string slash = \\ ;

// 我们使用batchcols来指定标题信息。
string batchcols = number,message ;
string number1 = 27730367747;
string message = startQuote + Testssss, thissss是一个逗号测试。请忽略plz。 + slash + endQuote;
Debug.WriteLine(message);

builtString.Append(startQuote);
builtString.Append(number1);
builtString.Append(逗号);
builtString.Append(斜杠);
builtString.Append(message);
builtString.Append(endQuote);

final = builtString.ToString();





在调试我的代码时,使用转义文字传递的字符串是:

引用:

\27730367747,\\\Testssss,thissss是一个逗号测试。请忽略plz.\\\\ \\\





但它用debug.writeline(字符串)输出:(我需要它在传入方法时才是这个。 )。有人可以澄清我哪里出错吗?

Quote:

27730367747,\Testssss,thissss是一个逗号测试。请忽略plz.\





我尝试过:



我已经尝试使用literal的字符串编码。我不知道为什么字符串不被识别为输出字符串。我不知道它是如何以及为什么需要编码。

解决方案

看看在C#中转义:字符,字符串,字符串格式,关键字,标识符 [ ^ ]。

干杯

岸堤

Hello

I am having problems trying to pass a string parameter to a secondary service API call.The method does not recognize the string that i am passing.My code:

StringBuilder builtString = new StringBuilder();
             string startQuote = "\""; //start quote
             string endQuote = "\""; //end quote
             string nextEntry = "\r\n"; //new line next entry
             string comma = ",";
             string slash = "\\";

             //we use batchcols to specifiy header info.
             string batchcols = "number,message";
             string number1 = "27730367747";
             string message = startQuote + "Testssss, thissss is a comma test.Please ignore plz." + slash + endQuote;
             Debug.WriteLine(message);

             builtString.Append(startQuote);
             builtString.Append(number1);
             builtString.Append(comma);
             builtString.Append(slash);
             builtString.Append(message);
             builtString.Append(endQuote);

             final = builtString.ToString();



while debugging my code the string im passing with escaped literals is:

Quote:

"\"27730367747,\\\"Testssss, thissss is a comma test.Please ignore plz.\\\"\""



But it outputs with debug.writeline(string) :(i need it to be this when passing into the method.).Can someone clarify where i am going wrong?

Quote:

"27730367747,\"Testssss, thissss is a comma test.Please ignore plz.\""



What I have tried:

I have tried string encoding with the literals.I Dont know why the string is not being recognized as the output string.I am not sure how and why it would need encoding.

解决方案

Have a look at Escaping in C#: characters, strings, string formats, keywords, identifiers[^].
Cheers
Andi


这篇关于使用转义文字的字符串编码理解。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆