verbatim-string

Replace \\\\ with \\ in C#

偶尔善良 提交于 2019-11-29 08:50:37
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 combinations of backslashes instead of using @ , but no luck. In C#, you can't have a string like "a\b\c\d" , because the \ has a special meaning: it creates a escape sequence together with a following letter (or combination of digits). \b represents actually a backspace, and \c and \d are invalid escape sequences (the compiler will complain about an

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

随声附和 提交于 2019-11-28 09:34:54
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? Steve All string literals in VB.NET are verbatim string literals. Simply write Dim str As String = "c:\folder1\file1.txt" VB.NET doesn't support inline control characters. So backslashes are always interpreted literally. The only character that needs to be escaped is the double quotation mark, which is escaped by doubling it, as you do in C# Dim s As String

Replace \\ with \ in C#

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 02:13:04
问题 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 combinations of backslashes instead of using @ , but no luck. 回答1: In C#, you can't have a string like "a\b\c\d" , because the \ has a special meaning: it creates a escape sequence together with a following letter (or combination of digits). \b represents

How do you use verbatim strings with interpolation?

跟風遠走 提交于 2019-11-27 19:12:25
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()); Becomes: string s = $"Adding \"{x}\" and {this.Y()} to foobar."; However, we have a lot of strings across multiple lines using verbatim strings (mainly SQL statements) like this: string s = string.Format(@"Result... Adding ""{0}"" and {1} to foobar: {2}", x, this.Y(), x.GetLog()); Reverting these to regular strings seems messy: string s = "Result...\r\n" + $"Adding \"{x}\" and {this.Y()

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

别等时光非礼了梦想. 提交于 2019-11-27 03:01:08
问题 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? 回答1: All string literals in VB.NET are verbatim string literals. Simply write Dim str As String = "c:\folder1\file1.txt" VB.NET doesn't support inline control characters. So backslashes are always interpreted literally. The only character that needs to be

How do you use verbatim strings with interpolation?

梦想的初衷 提交于 2019-11-26 22:46:49
问题 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()); Becomes: string s = $"Adding \"{x}\" and {this.Y()} to foobar."; However, we have a lot of strings across multiple lines using verbatim strings (mainly SQL statements) like this: string s = string.Format(@"Result... Adding ""{0}"" and {1} to foobar: {2}", x, this.Y(), x.GetLog());

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

旧巷老猫 提交于 2019-11-25 22:28:29
问题 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 = @\"this \\\"word\\\" is escaped\"; 回答1: Use a duplicated double quote. @"this ""word"" is escaped"; outputs: this "word" is escaped 回答2: Use double quotation marks. string foo = @"this ""word"" is escaped"; 回答3: For adding some more