简体   繁体   English

转义字符串中的 Unicode 字符 - C#、SeleniumWebDriver、VS2017

[英]Escape Unicode character in string - C#, SeleniumWebDriver, VS2017

I have a code that require to add a Unicode character in at the end of string line.我有一个代码需要在字符串行的末尾添加一个 Unicode 字符。 My environment is VS2017.我的环境是VS2017。 Language is C# (fairly new to me) and I am using selenium webdriver for all my test cases.语言是 C#(对我来说相当新),我的所有测试用例都使用 selenium webdriver。

The following seems very straight forward but I am having difficulty passing this unicode character.以下内容看起来非常简单,但我很难传递这个 unicode 字符。 The expected output should have the character instead of the text shown in here.预期的输出应包含字符而不是此处显示的文本。

string updatedMessage = "\u0003";
string start_of_line = "Hello World";

Console.WriteLine(start_of_line + updatedMessage);

Output
Hello World <specialcharacter><specialcharacter><specialcharacter><specialcharacter><specialcharacter>\u0003

Expected output
Hello World\u0003

So far, I have tried adding @"\" , or %"\"% but no luck so far.到目前为止,我已经尝试添加@"\"%"\"%但到目前为止没有运气。 I appreciate if anyone can suggest a solution.如果有人可以提出解决方案,我将不胜感激。 Thank you.谢谢你。

The issue is resolved.问题已解决。 There were empty string added before I paste my code in the VS.在我将代码粘贴到 VS 之前,添加了空字符串。 That was adding additional <specialcharacter> for me.那是为我添加了额外的<specialcharacter> I removed it by simply pasting in Notepad -> manually removed the empty strings and copy the code again to VS.我通过简单地在记事本中粘贴来删除它-> 手动删除空字符串并再次将代码复制到 VS。 Now, it is working as expected.现在,它按预期工作。

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

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