解决!!!!伙计们发生了一些奇怪的事情,它开始起作用我不知道为什么但我很高兴它终于有效了。谢谢你的帮助! 大家好。需要你的帮助。如何使用变音符号和空格编码和解码字符串?我正在寻找解决方案的时间,我现在所拥有的只是: 编辑:好的,所以感谢解决方案我得到了这个代码:
SOLVED!!!! Guys something strange happened and it started to work I don't know why but I'am glad it finally works. Thanks for helping me! Hi guys. Need your help. How can I encode and decode string with diacritic and spaces? I was looking for hours for solution and all I have now is: Ok, so thanks to solutions I've get this code:
public static string encode(string text) { byte[] mybyte = System.Text.Encoding.UTF8.GetBytes(text); string returntext = System.Convert.ToBase64String(mybyte); return returntext; } public static string decode(string text) { byte[] mybyte = System.Convert.FromBase64String(text); string returntext = System.Text.Encoding.UTF8.GetString(mybyte); return returntext; }但是我在System.Convert中收到错误Base-64 char数组的长度无效。 FromBase64String(text); 而且我也不确定这是否会占用字符串空格。 怎么办?感谢您的每一个回复。
But I'am getting error "Invalid length for a Base-64 char array" in System.Convert.FromBase64String(text); And I'am also not sure if this will take spaces in strings. What to do? Thanks for every reply.
推荐答案您的错误是使用ASCII。使用任何Unicode UTF,最好是UTF-8;它会起作用。当然,如果您将文本保存在纯文本文件中,请在匹配编码中进行。所有现代编辑都可以做到这一点,包括Visual Studio。 一个常见的错误观念是基于拉丁语的语言不使用Unicode。这不是真的。即使是纯美式英语也使用ASCII子集之外的Unicode代码点,印刷字符正确,引号等等。 请参阅: - - ...'和©还有更多。 你真的需要对Unicode有所了解。 请参阅: en.wikipedia/wiki/Unicode [ ^ ], http:// unicode/ [ ^ ], unicode/faq/utf_bom.html [ ^ ]。
这是因为您使用的ASCII编码非常有限,并且不支持变音字符。尝试其他编码,如UTF-8。 ( gnidesign.blogspot/2011 /04/c-how-to-encode-or-decode-string-to.html [ ^ ]) 祝你好运! It is because you use ASCII Encoding which is very limited and doesn't support diacritic characters. Try another encoding, like UTF-8. (gnidesign.blogspot/2011/04/c-how-to-encode-or-decode-string-to.html[^]) Good luck!
我发现这个有用的文章: HTML DECODE ENCODE [ ^ ] i found this useful article on this topic: HTML DECODE ENCODE[^]
更多推荐
C#如何解码和编码?
发布评论