将字符串转换为BASE62 [英] Convert a string into BASE62

查看:143
本文介绍了将字符串转换为BASE62的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将字符串转换为BASE62的c#代码,如下所示:

I'm looking for the c# code to convert a string into BASE62, like this:

http://www.molengo.com/base62/title/base62 -encoder-decoder

我需要那些用于URL编码的编码和解码方法.

I need those encode and decode-methods for URL-Encoding.

推荐答案

尝试使用此处提供的C#库,其中添加了一些扩展方法,使您可以将字节数组与BASE62相互转换.

Try the C# library available here which adds some extension methods to allow you to convert a byte array to and from BASE62.

如果源数据包含在字符串"中,那么您首先需要将字符串"转换为合适的字节数组.

If your source data is contained in a "string" then you would first need to convert your "string" to a suitable byte array.

但是要小心,使用正确的字符串进行字节转换调用.....您可能希望字节为ASCII字符或Unicode字节流等,例如Encoding.GetBytes(text)System.Text.ASCIIEncoding.ASCII.GetBytes(text);

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆