开发者

How do I escape strings which contain byte data in C#?

How do I escape strings in C#? I have strings which are the bytes fro开发者_如何转开发m a PNG and I need to escape them correctly in code to avoid compile errors...Any ideas?

So here is the type of code, I have which doesn't compile

public const string s =

"wewegliwewejwqejsadaskjda" +

"wewegliwewejqejsadaskjda" +

"wewegliwewejejsadaskjda" ;


The code you've given will compile, except that you've used constant instead of const. (Admittedly that's not valid Base64, as it contains the padding = character in the middle rather than at the end.) If this doesn't help, please post an example with this problem corrected but that still doesn't compile.

As Neil said, none of the characters in Base64 need escaping in C#.


Do you mean a Base 64 string? Usually if you see a PNG in string form, its base 64.

If not base 64, what type of encoding? Can you give us an example of what these strings look like?

EDIT:

To convert a Base64 string to a byte array (from which you can either save it as a PNG file or open it as an Image object) do this:

byte[] filebytes = Convert.FromBase64String(yourBase64String);


\ is the escape character for C#.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜