Link to home
Start Free TrialLog in
Avatar of mr_fnord1
mr_fnord1

asked on

c# Converting verbatim string to literal string

I am trying to feed string.Format from a textbox input. When escape characters are entered in the textbox, the Text property is treated as a verbatim string, and I can't find a way to have this verbatim string interpretted as if it was a literal string.

txtFormat.Text contains the following string:
'\t{0} - {1}\t\t{2}\r\n'

outputText.Text = string.Format(txtFormat.Text, f.Name, f.Length, f.CreationTime, f.DirectoryName, f.LastAccessTime, f.LastWriteTime));

outputText.Text displays:
'\tName - 9999\t\t1/1/1900\r\n'
instead of
'      Name - 9999            1/1/1900
'
Avatar of Justin_W
Justin_W

C# string escape characters are only usable within literal strings. The escape characters are automatically converted to the actual characters they represent by the compiler, so the escape characters never exist by the time the app runs. If you want to do what you desribed, you will need to create a string conversion method that replaces the escape characters the same way the compiler does.
ASKER CERTIFIED SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial