.net - On C# escape curly braces and a backslash after -


i trying format text can provide template rft text.

my string declared stringformater as:

var fulltitlestring = string.format(             cultureinfo.currentculture,             "{{\\test",             title,             filtername); 

but keep obtaining string "{\test". using single backslash results on errors @ not understand \t escaped character.

doing @"{{\test" yields "{\test". have looked on msdn documentation , other questions tell use backslash escaping character, doesn't seem work.

there 2 levevls of escaping here:

1. escaping string literals

in c# strings, backslash (\) used special character , needs escaped \. if resulting string should \\uncpath\folder string literal should var s = "\\\\uncpath\\folder".

2. escape format strings

string.format uses curly braces place holders, need escape them braces.

so let's have

string title = "mytitle"; string filtername = "filter"; 

then

string.format("{{\\test {0}, {1}}}", title, filtername); 

results in

{\test mytitle, filter} 

if want 2 curly braces @ beginning, need put 4 in format string:

string.format("{{{{\\test {0}, {1}}}", title, filtername); 

results in

{{\test mytitle, filter} 

if provide clear example of trying achieve, may tell correct format string.

side note: in c# 6 last example $"{{{{\\test {title}, {filtername}}}" (using string interpolation without explicitly calling string.format)

note: visual studio debugger shows unescaped string literal. if declare string string s = "\\" see both backslashes in debugger windows, if console.writeline(s) 1 backslash written console.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -