您的位置:程序门 -> .net技术 -> c#



求格式化字符算法一个


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求格式化字符算法一个[已结贴,结贴人:jiangchuandong]
发表于:2007-03-27 14:14:13 楼主
//想格式化数据为数据加字符的方式,如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++;
}
发表于:2007-03-27 14:16:241楼 得分:1
发表于:2007-03-27 14:38:272楼 得分:1
具体转换原理说清楚点     代码太乱
发表于:2007-03-27 15:17:583楼 得分:1
说清楚一下原理,看不明白
发表于:2007-03-27 15:24:194楼 得分:1
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;
}
发表于:2007-03-27 15:24:265楼 得分:1
1   ->   1   ,10-> a
那么100,1000呢?
发表于:2007-03-27 15:27:526楼 得分:1
帮顶一下,不明白想干啥
发表于:2007-03-27 15:30:367楼 得分:1
晕,我的这个算法也不行

因为我之前是进行excel的字母索引转换,所以进制是从1开始.
你这里是从0开始
发表于:2007-03-27 15:31:108楼 得分:1
楼主就是想做一个34进制转换
发表于:2007-03-27 15:36:559楼 得分:1
34进制?10-》a是34进制?更不明白了
发表于:2007-03-27 15:40:5610楼 得分:0
晕,我的这个算法也不行

因为我之前是进行excel的字母索引转换,所以进制是从1开始.
你这里是从0开始

你是怎么转的?说下原理
发表于:2007-03-27 15:43:3611楼 得分:0
up
发表于:2007-03-27 17:07:2912楼 得分:101
楼主就是三十四进制,其实用我那个改一下就行了,只是我在上班没时间改
楼主的三十四进制的表示方法为
0-33对应
0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,l,m,n,p,q,r,s,t,u,v,w,x,y,z

我以前做的特殊一些
十进制1-26分别对应
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
所以我刚开始的时候忘了这个问题,上面写的那个错得很厉害,但是原理是相通的
发表于:2007-03-27 18:30:5113楼 得分:0
ok,我試試
发表于:2007-03-29 14:01:5614楼 得分:10
发表于:2007-03-29 14:07:4915楼 得分:10
看看吧
发表于:2007-03-29 14:26:4916楼 得分:10
会笔算进制转换就会做的了~~~~
发表于:2007-04-10 15:49:3617楼 得分:10
的确   会笔算进制转换就会做的了


快速检索

最新资讯
热门点击