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
1
vote
1 answer

How work network paths in C#?

I'm having a doubt about this I tried to save a xmlDocument in a network device folder, not mapping. Where: config.plc.Path ="\\IpAdress\\folder\\"; doc.Save(config.plc.Path + "file.xml"); It was throwing an exception, and I just fixed it using…
Ferus7
  • 707
  • 1
  • 10
  • 23
1
vote
4 answers

How do I maintain multiple quotes quoted in a string in c#

So I have this piece of text that I need to be on a string so I can later add to a text file and should be like this string
Mr.Toxy
  • 357
  • 4
  • 19
1
vote
2 answers

How to have a verbatim string literal inside a verbatim string literal?

How can I stores something like the following string in C#: string mystring = @"CMD.AddParameters("@Pkey", SqlDbType.Int, Pkey.ToString());";
rtuner
  • 2,362
  • 3
  • 25
  • 37
1
vote
2 answers

Reading a string from a form as a verbatim string, \\ showing instead of \

I have the following property: public string InstanceName { get { return cbServerInstanceName.Text; } } where the input for cbServerInstanceName.Text = "ServerName\ PcName" This is showing up as "ServerName\\ PcName" I…
Hans Rudel
  • 3,433
  • 5
  • 39
  • 62
0
votes
1 answer

Triple-quote string C# vs F# heterogeneous behaviour

In C# the triple-quote string, or verbatim string behaves a little different from how F# behaves. In C#: { // just for indentation var message = """ this is a message from C# """; Console.WriteLine($"->{message}<-"); } dotnet…
santiago arizti
  • 4,175
  • 3
  • 37
  • 50
0
votes
1 answer

Adding a variable to the verbatim string literal

I am new to C# programming. I am trying to automate some API tests and passing payload in a POST request using RestSharp library. That payload looks like this public class Payload { public string firstPayload = @"{ " + "\n" + @" …
Sahil
  • 13
  • 5
0
votes
1 answer

C# - multiline verbatim string does not contains carriage return (\r) for new lines in Visual Studion 2022

We are facing issue when defining verbatim multiline strings (@"some string") in Visual Studio 2022. Although we are compling code on Windows machine and variable Environment.NewLine defines \r\n as new line, verbatim multiline string contains just…
Pavel Cermak
  • 1,215
  • 10
  • 13
0
votes
0 answers

c# verbatim interpolated string gives error

Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Unterminated…
0
votes
1 answer

How can I create a C# string verbatim without carriage return

I have a strange situation. When I do a string verbatim like this: string str = @"Hello World" The string is created with a "\r\n" so that it's "Hello \r\nWorld". I want it to be created with just the new line, no carriage return so that it's "\n"…
Tamer Rifai
  • 169
  • 2
  • 14
0
votes
1 answer

Unable to string.Format a C# multiline verbatim string when escaping curly braces

I am having issue with String.Format on a verbatim string with escaped curly braced. It's raising a FormatError() Exception:Message: System.FormatException : Input string was not in a correct format. String s = $@"{{ ""ver"":…
SwissFr
  • 178
  • 1
  • 12
0
votes
0 answers

Does the line-feed style of a C# here-document match Environment.Newline?

I have some unit-tests that appear to be failing because they depend on the assumption that the line-break inside a locally-compiled here-document string should match Environment.NewLine. I.e var testString=@"a multiline string"; //this…
NeilMacMullen
  • 3,339
  • 2
  • 20
  • 22
0
votes
1 answer

String.replace with verbatim string

I have a string which has several occurrences of the following text, exactly as it appears: \\(Y/A M D/J\\ The unclosed parenthesis is causing issues, so I thought I would remove the offending section, as I do not need that portion for my use of…
0
votes
2 answers

Verbatim string containing "#" recognized as a preprocessor directive

#if DEBUG string s = @" # text"; #endif If DEBUG is defined the above code builds without error using Visual Studio 2017. If DEBUG is not defined, the build fails with this error: error CS1024: Preprocessor directive expected The issue has…
ZunTzu
  • 7,244
  • 3
  • 31
  • 39
0
votes
0 answers

Using '@' in parameters names

I know the usage of verbatim prefix to avoid having to escape special characters all the time. For example: string s = @"c:\myPath"; However I just realized it is possible having something similar for parameters names. Example: public void…
John Smith1
  • 25
  • 1
  • 3
0
votes
1 answer

Syntax Error, but Copy/Pasted Query Text Works in SSMS

I am having an issue generating a SQL query using C#. To troubleshoot, I made the button that executes the query also display the query text in a textbox on the form. What's perplexing is that I get an error saying "Incorrect syntax near 'IF'"…
elmer007
  • 1,412
  • 14
  • 27