在c#中返回一个8位字母数字递增的值 [英] Return a 8 digit alphanumeric incremented value in c#

查看:128
本文介绍了在c#中返回一个8位字母数字递增的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想增加一个8位数的字母数字。

I want to increment a 8 digit alphanumeric.


我的8位数将是这样的东西

My 8 digit will some thing like this


前3个字符为ABC,其余5个数字应增加

first 3 characters will be ABC and rest 5 digits should increment


示例

ABC00001
ABC00002
ABC00003
.......
ABC00008
ABC00009
ABC0000A
ABC0000B
ABC0000C
ABC0000D
and soo on
........
........
ABC0000Y
ABC0000Z
ABC00010
ABC00012
and so on
.......




PS.Shakeer Hussain


PS.Shakeer Hussain

推荐答案

有趣的问题。你基本上想要在再次回绕之前从1到9再到A到Z计数。如果是ASCII字符集是一致然后我说从1开始并通过代码枚举,直到你到达Z,但你必须跳过非字母数字。

Interesting problem. You basically want to count from 1 to 9 and then A to Z before wrapping around again. If the ASCII char set was consistent then I'd say start at 1 and enumerate through the codes until you get to Z but you'd have to skip the non-alphanumerics.

你真正想要的是转换不幸的是,标准的ToString方法仅支持"正常"基数。但有人超过

SO
编写了一个快速函数来执行此操作。调用DecimalToArbitrarySystem(20,36)得到K,其中我相信是正确的。所以你可以使用常规计数器变量,但在将它连接到你的ABC值之前调用转换例程。

What you really want is to convert the number to base 36. Unfortunately the standard ToString method only supports the "normal" bases. However someone over on SO wrote a quick function to do it. Calling DecimalToArbitrarySystem(20, 36) yields K, which I believe is correct. So you could use a regular counter variable but call the conversion routine before concatenating it to your ABC value.

for (var index = 0; index < 40; ++index)
   Console.WriteLine(


" ABC {DecimalToArbitrarySystem(index,36).PadLeft(5,'0')}");
"ABC{DecimalToArbitrarySystem(index, 36).PadLeft(5, '0')}");

Michael Taylor 

http://www.michaeltaylorp3.net

Michael Taylor 
http://www.michaeltaylorp3.net


这篇关于在c#中返回一个8位字母数字递增的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆