开发者

Removing String Escape Codes

My program outputs strings like "Wzyryrff}av{v5~fvzu: Bb``igbuz~+\177Ql\027}C5]{H5LqL{" and the problem is the escape codes (\\\ instead of \, \177 instead of the ch开发者_如何学编程aracter, etc.)

I need a way to unescape the string of all escape codes (mainly just the \\\ and octal \027 types). Is there something that already does this?

Thanks

Reference: http://www.tailrecursive.org/postscript/escapes.html

The strings are an encrypted value and I need to decrypt them, but I'm getting the wrong values since the strings are escaped


It sounds more like it's encoded rather than simply escaped (if \177 is really a character). So, try decoding it.


There is nothing built in to do exactly this kind of escaping.

You will need to parse and replace these sequences yourself.

The \xxx octal escapes can be found with a RegEx (\\\d{3}), iterating over the matches will allow you to parse out the octal part and get the replacement character for it (then a simple replace will do).

The others appear to be simple to replace with string.Replace.


If the string is encrypted then you probably need to treat it as binary and not text. You need to know how it is encoded and decode it accordingly. The fact that you can view it as text is incidental.


If you want to replace specific contents you can just use the .Replace() method.

i.e. myInput.Replace("\\", @"\")

I am not sure why the "\" is a problem for you. If it its actually an escape code then it just should be fine since the \ represents the \ in a string.

What is the reason you need to "remove" the escape codes?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜