字母序列递增,即A+1=B,B+2=D,ASCII

实际遇到的问题是 单号15001订单的15001-A自动生成15001-B,15001-C....

//说明:以15001-A为基准生成15001-B
string maxno ="15001-A";
//1.把订单号和后缀分隔开
string[] strmax = maxno.Split('-');//以‘-’分割字符串,把150001和A分开
//2.转换ASCII码值需要字符串为char型,转换之
char sort = (char)strmax[1][0];//strmax[1]为数组第2个元素,strmax[1][0]为数组第2个元素的第一个字符
//3.转换为ASCII对应的数字
 int ascii = (int)sort;//字母A转换为ASCII值65
//4.序号+1
 int ascii2 = ascii + 1;//序号加1,为66
//5.转换回字母
string sort2 = ((char)ascii2).ToString(); //再转换为字母B
//6.返回拼接后的字符串15001-B
return strmax[0] + "-" + sort2.ToString();
原文地址:https://www.cnblogs.com/luoxueningchen/p/5059793.html