What are the differences in string literals between C#, Visual Basic.NET, and Managed C++?

旧巷老猫 提交于 2019-12-11 03:55:36

问题


I'm referring to the syntax for writing strings in code, including multiline strings and verbatim strings.

(Context: I'm working on a tool that scans code, and it's important to determine when tokens are inside a string.)

Thanks!


回答1:


Here's a quick breakdown between languages

  • Managed C++: Supports string literals much in the way that vanilla C,C++ or C# does. That is strings are designated by " and allow for character escape sequences in the middle via a \.
  • C#: Supports normal string literals (essentially same syntax as Managed C++) and verbatim string literals. Verbatim string literals start with @" and do not support character escape sequences (with the exception of "" which designates a single "). They can span multiple lines and all whitespace is significant
  • VB.Net: Strings are delimited by "'s and no escape sequences are supported



回答2:


basic syntax is same

string csharp;    // C#
string cPlusPlus; // C++

see following for better insight

string class (C++) and string class (C#)



来源:https://stackoverflow.com/questions/2464444/what-are-the-differences-in-string-literals-between-c-visual-basic-net-and-ma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!