求格式化字符算法一个
//想格式化数据为数据加字符的方式,如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++;
}
------解决方案--------------------顶
------解决方案--------------------具体转换原理说清楚点 代码太乱
------解决方案--------------------说清楚一下原理,看不明白
------解决方案--------------------static char[] IntIndexToLetter(int no)
{
List <int> intArray = new List <int> ();
while (no > 0)
{
if (no % 34 == 0)
{
intArray.Add(34);
no = (no - 34) / 34;
}
else
{
intArray.Add(no % 34 + 1);
no = no / 34;
}
}
intArray.Reverse();
char[] chrArray = new char[intArray.Count];
for (int i = 0; i < intArray.Count; i++)
{
if (intArray[i] <= 10)
{
chrArray[i] = (char)(intArray[i] + 47);
}
else if (intArray[i] - 10 + 64 < (int) 'I ')
{
chrArray[i] = (char)(intArray[i] - 10 + 64);
}
else if (intArray[i] - 10 + 64 < (int) 'O ')
{
chrArray[i] = (char)(intArray[i] - 10 + 64 + 1);
}
else
{
chrArray[i] = (char)(intArray[i] - 10 + 64 + 2);
}
}
return chrArray;
}
------解决方案--------------------1 -> 1 ,10-> A
那么100,1000呢?
------解决方案--------------------