生成一系列数字,从1,2,3,...,A,B ...... Z,10,11,12,13 ...... 19,1A。 [英] Generate a sequence of numbers from 1, 2, 3, ...9, A , B...Z, 10, 11, 12, 13, ......19, 1A.

查看:61
本文介绍了生成一系列数字,从1,2,3,...,A,B ...... Z,10,11,12,13 ...... 19,1A。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...



我想以这种方式生成一系列独特的数字...



1,2,3,... 9,A,B ...... Z,10,11,12,13,...... 19,1A,1B ....... 1Z ,20,21 ...... ZZZZZZZZZZ,10位数。



类似于十六进制系列,但直到Z ...



我想.NET中存在一些内置机制来生成这个系列。但我没有名字可以研究它。



我可以编写自己的代码来生成这个序列,但我总是喜欢使用.net内置的构造比一个自定义代码。



任何人都可以指导我这个方向..特别是,这个序列被称为是什么,并且是任何可用于生成此内容的内置构造。 net ???

解决方案

base-36没有内置任何东西,但如果你在网上搜索有类似的东西:



基础36类型的.NET(C#) [ ^ ]



位数表示您将拥有的最大数字,10位数的基数为36的数字非常大。


我怀疑是否有一个''内置构造''。您可以很容易地生成这样的序列。



[更新]

引用:

如果您有任何解决方案,请提供给我

虽然这与以下内容形成鲜明对比:

引用:

我可以编写自己的代码来生成这个序列







我们走了......



  class  SeqGen 
{
char [] code;

public SeqGen()
{
code = new char [ 10 ];
for int n = 0 ; n< 10; n ++)code [n] = ' 0';
}

private void inc( int pos)
{

if (code [pos] == ' 9'
code [pos] = ' A';
else if (code [pos] == ' Z'
{
if (pos = = 0
throw new 异常( overflow);
code [pos] = ' 0';
inc(pos-1);
}
else
{
code [pos] ++;
}
}

public void inc( )
{
inc( 9 );
}
public 覆盖 string ToString()
{
return new string (code).TrimStart( new char [] { ' 0'});
}
}





用法示例:

 计划
{
静态 void Main()
{
SeqGen sg = new SeqGen();
for int i = 0 ; i < 100 ; i ++)
{
sg.inc ();
Console.WriteLine( i = {0},code = {1}, i,sg.ToString());
}
}
}





[/ Update]


Hi...

I want to generate a unique sequence of numbers in this fashion...

1, 2, 3, ...9, A , B...Z, 10, 11, 12, 13, ......19, 1A, 1B.......1Z, 20, 21......ZZZZZZZZZZ in 10 digits.

Similar to the hexadecimal series but till Z ...

I guess something inbuilt mechanism exist in .NET to generate this series. But I dont have a name to research about it.

I can write my own code to generate this sequence, but I always prefer to use the .net built in constructs than a custom code.

Can anybody guide me in this direction.. particularly, what this sequence is called as and is any built in construct available for generating this in .net ???

解决方案

Nothing built in for base-36, but there are things like this if you search the net:

Base 36 type for .NET (C#)[^]

The number of digits represents the biggest number you will have, a 10 digit base-36 number is very very large.


I doubt there is a ''built in construct'' for this. You may very easily generate yourself such a sequence.

[Update]

Quote:

if you have any solution for this, please provide me

Albeit this is a bit in contrast with:

Quote:

I can write my own code to generate this sequence




Here we go...

class SeqGen
{
  char [] code;

  public SeqGen()
  {
      code = new char[10];
      for(int n=0; n<10; n++) code[n]='0';
  }

  private void inc(int pos)
  {

    if (code[pos] == '9')
        code[pos] = 'A';
    else if (code[pos]=='Z')
    {
      if ( pos==0)
        throw new Exception("overflow");
      code[pos] = '0';
      inc(pos-1);
    }
    else
    {
      code[pos]++;
    }
  }

  public void inc()
  {
    inc(9);
  }
  public  override string ToString()
  {
     return new string(code).TrimStart(new char [] {'0'});
  }
}



Usage example:

class Program
 {
   static void Main()
   {
     SeqGen sg = new SeqGen();
     for (int i = 0; i < 100; i++)
     {
       sg.inc();
       Console.WriteLine("i={0}, code={1}", i, sg.ToString());
     }
   }
 }



[/Update]


这篇关于生成一系列数字,从1,2,3,...,A,B ...... Z,10,11,12,13 ...... 19,1A。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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