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
5
votes
5 answers

regular expression for c# verbatim like strings (processing ""-like escapes)

I'm trying to extract information out of rc-files. In these files, "-chars in strings are escaped by doubling them ("") analog to c# verbatim strings. is ther a way to extract the string? For example, if I have the following string "this is a…
MartenBE
  • 744
  • 1
  • 5
  • 20
4
votes
6 answers

C# - Illegal characters in path

I have a database table that containing file paths of excel files that I import using a C# script. The script works fine unless the filepath contains spaces e.g. C:\Temp\My Excel File.xls and I get an Illegal characters in path error message.…
Simon
  • 1,293
  • 5
  • 21
  • 39
3
votes
3 answers

Adding string to verbatim string literal

I am trying to construct a raw json string as below to send it out in http request var requestContent = @"{ ""name"": ""somename"", ""address"": ""someaddress"" }"; Instead of having name and address value…
Frank Q.
  • 6,001
  • 11
  • 47
  • 62
3
votes
3 answers

.NET StringBuilder and verbatim string literal

In my Application there is a class that works with PdfSharp to generate some PDF reports. I specified output folder as a string with verbatim string file_path = @"D:\Intranet\Students\DailyMarks\"; Also there is a StringBuilder that generates file…
Iskander Raimbaev
  • 1,322
  • 2
  • 17
  • 35
3
votes
4 answers

Is Verbatim or escaping the preferred way to deal with quote-rich strings in C#?

To escape or to verbatim, that is my question. I need to programmatically send a couple of commands to a (Zebra QLn220) printer in C#, specifically: ! U1 setvar "power.dtr_power_off" "off" -and: ! U1 setvar "media.sense_mode" "gap" Due to the…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
3
votes
4 answers

Why does removing new-lines from my verbatim string return only the last line?

I have the following code: string test = @"1 2 3"; This line: Console.WriteLine(test.Replace("\n", "")); //3 prints "3", instead of "123", which is what I expected. Why does this method return only the last line of my string, and how can I…
Daniel
  • 2,944
  • 3
  • 22
  • 40
2
votes
2 answers

SwiftUI how to change font and color for email address in Text

If I didn't use verbatim with Text Ex: Text("Reach out to us on info@eyva.io for any queries!") .foregroundColor(Color.white) .font(Font.custom("Poppins-Regular", size: getFontSize(value: 16))) Output: And,…
2
votes
4 answers

Verbatim string is missing carriage return

I have encountered a strange issue today. I have a verbatim string like this: var s = @" 0 1 0 0" i.e. there is a new line after the one. My Environment.NewLine is set to \r\n This is part of a unit test and the tests have been…
Tim Rutter
  • 4,549
  • 3
  • 23
  • 47
2
votes
1 answer

Latex printing single slash, backslash r, backslash n

I want the following line inside a *.tex file to be printed "as is": while (tmp[0] == '\r' || tmp[0] == '\n') {tmp++;} When I wrap it in a \verb command like this: \verb"while (tmp[0] == '\r' || tmp[0] == '\n') {tmp++;}" it doesn't work, and I…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
2
votes
5 answers

Replace \\ with \ in C#

I have a long string (a path) with double backslashes, and I want to replace it with single backslashes: string a = "a\\b\\c\\d"; string b = a.Replace(@"\\", @"\"); This code does nothing... b remains "a\\b\\c\\d" I also tried different…
user990635
  • 3,979
  • 13
  • 45
  • 66
1
vote
1 answer

Why is the address sign @ used in building SQL command?

Possible Duplicate: What's the @ in front of a string for .NET? What is that @ in this SQL command doing? Would its first and second occurrence serve the same purpose? static DataTable StaffsGetProjectIDHRCoordinators(SqlConnection conn, string…
KTmercury
  • 93
  • 3
1
vote
1 answer

C# regex does not allow special characters correctly?

For example I have the following string: thats a\n\ntest\nwith multiline \n\nthings... I tried to use the following code which does not work correctly and still hasn't all chars included: string text = "thats a\n\ntest\nwith multiline \n\nthings…
RoyBlunk
  • 91
  • 8
1
vote
1 answer

How to encode doube quotes when using CSharpSyntaxTree.ParseText (Roslyn)

I am trying to use the Roslyn compiler to dynamically generate an assembly & class. When I call Emit I get and error about the double quoted value in the base constructor in the following: How should I encode the double-quotes in the string I pass…
AwkwardCoder
  • 24,893
  • 27
  • 82
  • 152
1
vote
1 answer

Can we escape verbatim string containing curly braces in Python?

I am using pyodbc library to connect my Python program to a SQL Server database. I want to construct Connection String using a verbatim string as under. connection_string = f"DRIVER={SQL…
Merin Nakarmi
  • 3,148
  • 3
  • 35
  • 42
1
vote
1 answer

Saving/loading a verbatim string to a text file

I'm a month or so into my coding journey and I'm currently writing my first program. It allows the saving and organization of code snippets into an easily searched library. Screenshot I am currently using two lists to store the data (one for entry…
DuMonYu
  • 13
  • 4