我正在寻找将字符串转换为 BASE62 的 C# 代码,如下所示:
http://www.molengo.com/base62/title/base62-encoder-decoder
我需要那些用于 URL 编码的编码和解码方法。
BINARY 到 TEXT 编码方案的背景:
https://en.wikipedia.org/wiki/Base62
https://en.wikipedia.org/wiki/Base64
BASE62编码方案的很好的解释:
https://www.codeproject.com/Articles/1076295/Base-Encode
尝试使用此处提供的 C# 库,它添加了一些扩展方法,允许您在字节数组与 BASE62(二进制到文本编码方案)之间进行转换。
github上有很多base62库,看看:
- https://github.com/JoyMoe/Base62.Net
- https://github.com/ghost1face/base62
- https://github.com/rossdempster/base62csharp
-
https://github.com/renmengye/base62-csharp(下面声称它不起作用......向他们提出任何问题)
如果您的源数据包含在“字符串”中,那么您首先需要将“字符串”转换为合适的字节数组。
但要小心,使用正确的字符串到字节转换调用...因为您可能希望字节是 ASCII 字符或 Unicode 字节流等,即Encoding.GetBytes(text)
or System.Text.ASCIIEncoding.ASCII.GetBytes(text);
, etc
byte[] bytestoencode = .....
string encodedasBASE62 = bytestoencode.ToBase62();
.....
byte[] bytesdecoded = encodedasBASE62.FromBase62();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)