Convert a string into BASE62(将字符串转换为 BASE62)
问题描述
我正在寻找将字符串转换为 BASE62 的 c# 代码,如下所示:
http://www.molengo.com/base62/title/base62-encoder-decoder
我需要那些用于 URL 编码的编码和解码方法.
BINARY to 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) 或 System.Text.ASCIIEncoding.ASCII.GetBytes(text); 等
byte[] bytestoencode = .....string encodingasBASE62 = bytestoencode.ToBase62();......byte[] bytesdecoded = encodeasBASE62.FromBase62();I'm looking for the c# code to convert a string into BASE62, like this:
http://www.molengo.com/base62/title/base62-encoder-decoder
I need those encode and decode-methods for URL-Encoding.
Background on BINARY to TEXT Encoding schemes:
https://en.wikipedia.org/wiki/Base62
https://en.wikipedia.org/wiki/Base64
Good explanation of the BASE62 encoding scheme:
https://www.codeproject.com/Articles/1076295/Base-Encode
Try the C# libraries available here which adds some extension methods to allow you to convert a byte array to and from BASE62 (binary-to-text encoding schemes).
Plenty of base62 libraries on github, have a look:
- https://github.com/JoyMoe/Base62.Net
- https://github.com/ghost1face/base62
- https://github.com/rossdempster/base62csharp
- https://github.com/renmengye/base62-csharp (claims below that it doesn't work...raise any issues with them)
If your source data is contained in a "string" then you would first need to convert your "string" to a suitable byte array.
But be careful, to use the correct string to byte conversion call....as you may want the bytes to be the ASCII characters, or the Unicode byte stream etc i.e. Encoding.GetBytes(text) or System.Text.ASCIIEncoding.ASCII.GetBytes(text);, etc
byte[] bytestoencode = ..... string encodedasBASE62 = bytestoencode.ToBase62(); ..... byte[] bytesdecoded = encodedasBASE62.FromBase62();
这篇关于将字符串转换为 BASE62的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将字符串转换为 BASE62
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 将数据集转换为列表 2022-01-01
