Questions tagged [verbatim-string]

C# supports two forms of string literals: regular string literals and verbatim string literals. A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character

In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals. A verbatim string literal may span multiple lines.

57 questions
9 answers

What's the @ in front of a string in C#?

This is a .NET question for C# (or possibly, but I am trying to figure out what's the difference between the following declarations: string hello = "hello"; vs. string hello_alias = @"hello"; Printing out on the console makes no…
  • 7,519
  • 3
  • 18
  • 11
6 answers

Can I escape a double quote in a verbatim string literal?

In a verbatim string literal (@"foo") in C#, backslashes aren't treated as escapes, so doing \" to get a double quote doesn't work. Is there any way to get a double quote in a verbatim string literal? This understandably doesn't work: string foo =…
  • 27,905
  • 33
  • 92
  • 139
1 answer

How to use verbatim strings with interpolation?

In C# 6 there is a new feature: interpolated strings. These let you put expressions directly into code. Rather than relying on indexes: string s = string.Format("Adding \"{0}\" and {1} to foobar.", x, this.Y()); the above becomes: string s =…
  • 150,284
  • 78
  • 298
  • 434
7 answers

How to do a verbatim string literal in VB.NET?

How do you do a verbatim string literal in VB.NET? This is achieved in C# as follows: String str = @"c:\folder1\file1.txt"; This means that the backslashes are treated literally and not as escape characters. How is this achieved in VB.NET?
  • 22,579
  • 65
  • 193
  • 321
3 answers

How do I escape " in verbatim string?

I am a bit new to c#, and i am stuck at this point, I have a regular string, where i made use of \ to escape ", escape here means that to escape the compilers interpretation of ", and get " printed on the screen, and i get the expected…
Srinivas Cheruku
  • 1,314
  • 3
  • 11
  • 19
5 answers

multiline formatting for verbatim strings in c# (prefix with @)

I love using the @"strings" in c#, especially when I have a lot of multi-line text. The only annoyance is that my code formatting goes to doodie when doing this, because the second and greater lines are pushed fully to the left instead of using the…
Brady Moritz
  • 8,624
  • 8
  • 66
  • 100
1 answer

New line in a verbatim string literal

I have a string as follows: string example = @"string str = ""forty-two""; char pad = '*'; the output is in a single line as follows: string str = "forty-two"; char pad = '*'; I need the output as follows: string str = "forty-two"; char pad =…
3 answers

How to use string interpolation and verbatim string together to create a JSON string literal?

I'm trying to create a string literal representing an array of JSON objects so I thought of using string interpolation feature as shown in the code below: public static void MyMethod(string abc, int pqr) { string p =…
  • 24,161
  • 21
  • 159
  • 240
7 answers

Putting \" in verbatim string with C#

I need to print a "b" c with the vebatim string, I posed another question about multiple line code template here. I tried with verbatim string as follows : using System; class DoFile { static void Main(string[] args) { string…
  • 182,215
  • 215
  • 566
  • 871
2 answers

C# Verbatim String Line Breaks: CRLF, CR, or LF?

I ran into an interesting problem today where my tests were failing consistently on the build machine when they worked just fine on my machine even using the same configuration. When I looked at the differences output by Assert.AreEqual in the…
  • 3,551
  • 1
  • 28
  • 38
3 answers

Adding a string to the verbatim string literal

I have a path that is named defaultPath I want to add it into this verbatim string literal but can quite get the quotes around it. @"""C:\Mavro\MavBridge\Server\MavBridgeService.exe"" /service /data ""..\Data""" I was trying to add…
  • 8,520
  • 7
  • 41
  • 77
7 answers

Escaping verbatim string literals

I have the following string which won't compile: String formLookupPull = @"SELECT value1, '"+tableName+"', '"+columnName+"' FROM lkpLookups WHERE ""table"" = '" + tableName + "' and ""field"" = '" + columnName + "';"; The offending sections are…
Brian Sweeney
  • 6,693
  • 14
  • 54
  • 69
3 answers

Interpolating a string stored in a database

We would like to maintain the emails that are sent from our ASP.NET Web Application in a database. The idea was that the format of emails are stored in a database. The problem is that emails should include order specific information, e.g.: Thank…
  • 103
  • 2
  • 8
2 answers

C# like verbatim string in Rust?

I am looking for a verbatim strings in Rust (like in C# with @"This is a string and here ""I am between quotes without making a fuss"""). Is there something similar?
Natalie Perret
  • 8,013
  • 12
  • 66
  • 129
1 answer

Preventing VB.NET's multiline/verbatim string from destroying your entire code file?

Let's say you have a module that's several hundreds of lines long. At the very top of your code file, you go to start up a string, so you type a quote. Total wreckage ensues as the string remains unterminated for a time, causing everything within…
  • 10,457
  • 39
  • 119
  • 206
2 3 4