C#如何解码和编码?

编程入门 行业动态 更新时间:2024-10-28 21:21:05
本文介绍了C#如何解码和编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

解决!!!!伙计们发生了一些奇怪的事情,它开始起作用我不知道为什么但我很高兴它终于有效了。谢谢你的帮助! 大家好。需要你的帮助。如何使用变音符号和空格编码和解码字符串?我正在寻找解决方案的时间,我现在所拥有的只是: 编辑:好的,所以感谢解决方案我得到了这个代码:

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 [ ^ ]。
-SA
Your mistake is using ASCII. Use any of Unicode UTFs, preferably UTF-8; and it will work. Of course, if you save text in plain text file, do it in matching encoding. All modern editor can do it, including Visual Studio. One pretty usual misconception is that Latin-based languages don't use Unicode. This is not true. Even pure American English uses Unicode code point outside the ASCII subset, in typographically correct dash characters, quotation marks, etc. See: — – … " " ' © and a lot more. You really need some understanding of Unicode. Please see: en.wikipedia/wiki/Unicode[^], unicode/[^], unicode/faq/utf_bom.html[^].
—SA

这是因为您使用的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#如何解码和编码?

本文发布于:2023-10-30 13:32:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!