求格式化字符算法一个

jiangchuandong jiangchuandong 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
//想格式化数据为数据加字符的方式,如1 -> 1 ,10->A,同时去除I,O等易混字符,现在的算法在上1000的时候,格式话数据就存在问题,eg:999格式化为ZZ了,1000应该是A00

string strWaterNo = StartValue;
string strWaterNoChr = string.Empty;
int WaterNoCnt = 0;

while (WaterNoCnt < Length - TempDocNo.Length)
{
int WaterNoDigit = int.Parse(((int.Parse(strWaterNo) / int.Parse(Math.Pow(32, WaterNoCnt).ToString())) % 32).ToString());//計算公式111/0%32,111/32%32

if (WaterNoDigit < 10)
{
// WaterNoChr = "0" + WaterNoDigit.ToString()+ WaterNoDigit.ToString();
string strTemp = "0" + WaterNoDigit.ToString();
strWaterNoChr = Convert.ToString(strTemp).Substring(strTemp.Length - 1, 1) + strWaterNoChr;
}
else
{
int intTempWaterNoDigit = WaterNoDigit + 55;
int intTempWaterCharShift = 0;
if (intTempWaterNoDigit >= 72)//减少判断次数,字母I之前不用判断
{
if (intTempWaterNoDigit + intTempWaterCharShift >= (int)'I')
intTempWaterCharShift = intTempWaterCharShift + 1;

if (intTempWaterNoDigit + intTempWaterCharShift >= (int)'O')
intTempWaterCharShift = intTempWaterCharShift + 1;

if (intTempWaterNoDigit + intTempWaterCharShift >= (int)'U')
intTempWaterCharShift = intTempWaterCharShift + 1;

if (intTempWaterNoDigit + intTempWaterCharShift >= (int)'V')
intTempWaterCharShift = intTempWaterCharShift + 1;
}
strWaterNoChr = Convert.ToString((char)(intTempWaterNoDigit + intTempWaterCharShift)) + strWaterNoChr;
}
WaterNoCnt++;
}
...全文

相关推荐

评论 17
收藏 已收藏
分享
返回顶部
jiangchuandong
C# 111,129 成员 642,540 内容