private const string initValue = "A0000001";

        private static string cs = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        public static string AddOne(string str)
{
if (str == string.Empty)
{
return initValue;
}
Int64 num = StringToNumber(str);
return NumberToString(++num);
} public static Int64 StringToNumber(string str)
{
int leg = str.Length;
double num = ;
if (leg != )
{
for (int i = ; i < leg; i++)
{
if (str[i] != '')
{
num += cs.IndexOf(str[i]) * Math.Pow(, leg - - i);
}
}
}
return Convert.ToInt64(num);
} public static string NumberToString(Int64 num)
{
string str = string.Empty;
while (num >= )
{
str = cs[(int)(num % )] + str;
num = num / ;
}
return cs[(int)num] + str;
}

2019-8-30改进的版本

class Program {
static void Main(string[] args) {
string curr = "ZZZZZZ";
Console.WriteLine("原始值:" + curr);
Int64 num = Scale.ToInt64(curr);
Console.WriteLine("转成Int64:" + num);
Console.WriteLine("根据Int64转成进制:" + Scale.ToCurr(num));
Console.ReadLine();
}
}
public static class Scale {
/// <summary>
/// 进制符号字符串
/// </summary>
private static string scString = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
/// <summary>
/// 字符集,可以根据编号索引拿到字符
/// </summary>
private static char[] scArray = scString.ToCharArray();
/// <summary>
/// 字符字典,可以根据字符拿到编号索引
/// </summary>
private static Dictionary<char, int> scDic = ToCharDic();
/// <summary>
/// 根据字符串反馈进制数
/// </summary>
public static int Len { get { return scString.Length; } } /// <summary>
/// 将字符串处理成字符字典
/// </summary>
private static Dictionary<char, int> ToCharDic() {
Dictionary<char, int> dic = new Dictionary<char, int>();
for (int i = 0; i < scArray.Length; i++) {
dic.Add(scArray[i], i);
}
return dic;
}
/// <summary>
/// 根据传入的字符符号定义进制,字符符号不能重复,模拟十进制字符串为:0123456789
/// </summary>
public static void SetScale(string scaleString) {
scString = scaleString;
scArray = scString.ToCharArray();
scDic = ToCharDic();
}
/// <summary>
/// 将Int64转成当前进制字符串
/// </summary>
public static string ToCurr(long num) {
string curr = "";
while (num >= Len) {
curr = scArray[num % Len] + curr;
num = num / Len;
}
curr = scArray[num] + curr;
return curr;
}
/// <summary>
/// 将当前进制字符串转成Int64
/// </summary>
public static long ToInt64(string curr) {
double num = 0;
for (int i = 0; i < curr.Length; i++) {
num += scDic[curr[i]] * Math.Pow(Len, curr.Length - 1 - i);
}
return Convert.ToInt64(num);
}
}

  

最新文章

  1. 使用socket方式连接Nginx优化php-fpm性能
  2. How to upgrade workflow assembly in MOSS 2007
  3. 【转】bShare分享插件的使用
  4. Keil: warning: A1581W: Added 2 bytes of padding at address
  5. matlab读取指定路径下的图像
  6. C#list泛型集合
  7. Custom draw 和 Owner draw 的区别
  8. phabricator 搭建
  9. instance “error” 了怎么办?- 每天5分钟玩转 OpenStack(159)
  10. 看懂 ,学会 .NET 事件的正确姿势
  11. Mysql和mongo安装配置
  12. PC逆向之代码还原技术,第四讲汇编中减法的代码还原
  13. 如何使用mybatis插入数据之前就具生成id值
  14. JS调用本地设备
  15. 08机器学习实战之BP神经网络
  16. configServer的高可用
  17. 读书笔记5基于matplotlib画图
  18. Learn Rails5.2- ActiveRecord: sqlite3的用法, Query查询语法。乐观锁和悲观锁案例,查询语法includes(), 多态关联,destory和delete, Scope, Validats, Migrations
  19. 测试工具APPScan安装与使用教程
  20. 可执行jar包

热门文章

  1. v-distpicker 一个好用的三级联动的插件
  2. Puppeteer自动化测试cnode.js中文社区
  3. 微信小程序app.json文件常用全局配置
  4. mysql5.7 基于gtid的主从复制
  5. Python常用三方库安装
  6. rabbitmq使用延迟时报异常
  7. Delphi 消息函数 SendMessage函数
  8. 【JVM】符号引用和直接引用
  9. ORACLE动态sql在存储过程中出现表或视图不存在的解决方法
  10. 工程师技术(二):postfix基础邮件服务、postfix空客户端邮件服务、搭建mariadb数据库系统、配置一个数据库、使用数据库查询