c# - Translate string literals to their actual values -
this question has reply here:
how can unescape , reescape strings in .net? 4 answersnote: didn't want create question long, "how" question title translates "is there method in .net framework".
just reminder:
\n if above printable representation of string, internal version 1 character, not two, code 0x0a.
however write:
string s = "\\n"; // 3 characters in editor which translates internal representation of 2 characters \ , n. not 0x0a character!
but accomplish this. i.e. have in string data, know printable representation of string. , convert internal representation (something c# compiler time).
string printable = "\\n"; string internal_ = convert(printable); internal_ hold 1 character now, of code 0x0a.
question: there ready use (!) function such conversion?
you seek utilize system.text.regularexpressions.regex.unescape static method:
string internal_ = regex.unescape(printable); but unfortunately applicable regex command characters.
test:
var chars = internal_.tochararray(); the chars array has 1 element code 0x0a.
c# string
No comments:
Post a Comment