本文介绍了COM pressing大数目(或字符串),以较小的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

这里的情况是:一个ASP.NET页面下面的查询字符串参数。MyServer.com/ShowSomething.aspx?IDs=1000000012,1000000021,1000000013,1000000022& ...

Here is the situation: An ASP.NET page has following query string parameter.MyServer.com/ShowSomething.aspx?IDs=1000000012,1000000021,1000000013,1000000022&...

下面的ID参数将始终具有数字分离的东西,在这种情况下,。目前有4个数字,但通常他们会在3-7之间。

Here IDs parameter will always have numbers separated by something, in this case ",". Currently there are 4 numbers but normally they would be in between 3-7.

现在,我在寻找方法来各大数字转换成以上最小的可能值;特别是COM pressing 标识查询字符串参数的值。在这两方面,COM pressing每个数字算法或COM pressing的整体价值标识查询字符串参数的欢迎。

Now, I am looking for method to convert each big number from above into smallest possible value; specifically compressing value of IDs query string parameter. Both, compressing each number algorithm or compressing whole value of IDs query string parameter are welcome.

1)恩code或去code是不是一个问题;只是COM pressing的值ID查询字符串参数。2)创建用于标识一些独特的小值,然后从一些数据源检索它的值超出了范围。

1) Encode or decode is not an issue; just compressing the value IDs query string parameter.2) Creating some unique small value for IDs and then retrieving its value from some data source is out of scope.

请提供一些算法融为一体preSS这样的大号码为ID查询字符串参数的COM preSS值较小的值或算法。

推荐答案

您基本上需要那么多的空间,你的号码,因为使用的是基地10重新present他们。的改进是使用底座16(十六进制)。因此,例如,你可以重新present 255(3位)为ff(2位)。

You basically need so much room for your numbers because you are using base 10 to represent them. An improvement would be to use base 16 (hex). So for example, you could represent 255 (3 digits) as ff (2 digits).

您可以通过使用一个更大的基数...的一套有效的查询字符串参数中的所有字符进一步采取这一概念:

You can take that concept further by using a much larger number base... the set of all characters that are valid query string parameters:

A-Z,A-Z,0-9,'。'' - ','〜','_','+'

A-Z, a-z, 0-9, '.', '-', '~', '_', '+'

这是给你的67个字符的基地(见维基百科上的查询字符串工作)。

That gives you a base of 67 characters to work with (see Wikipedia on QueryString).

看一看this SO帖子的方法来转换基地10到任意数量的基地。

Have a look at this SO post for approaches to converting base 10 to arbitrary number bases.

编辑:

在链接的SO后,看看这一部分:

In the linked SO post, look at this part:

string xx = IntToString(42, 
            new char[] { '0','1','2','3','4','5','6','7','8','9',
            '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',
            'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x'});

这几乎是你所需要的。只需通过添加几个字符,它缺少展开:

That's almost what you need. Just expand it by adding the few characters it is missing:

yz.-〜_ +

该职位缺少一个方法去回基地10。我不打算把它写:-),但过程是这样的:

That post is missing a method to go back to base 10. I'm not going to write it :-) but the procedure is like this:

定义一个计数器,我会打电话总和。

Define a counter I'll call TOTAL.

看在右侧大多数字符,并找到它的数组中的位置。
TOTAL =(字符的阵列中的位置)例如:输入BA1。 TOTAL现在为1(自1是在该阵列中的位置1)

Look at the right most character and find it's position in the array.
TOTAL = (the position of the character in the array)Example: Input is BA1. TOTAL is now 1 (since "1" is in position 1 in the array)

现在先看下第一个离开的性格,发现它的数组中的位置。TOTAL = + 47 *(在字符阵列中的位置)例如:输入BA1。总现在是(47 * 11)+ 1 = 518

Now look at the next character left of the first one and find it's position in the array.TOTAL += 47 * (the position of the character in the array)Example: Input is BA1. TOTAL is now (47 * 11) + 1 = 518

现在看下面的previous人离开的性格,并找到它的数组中的位置。TOTAL = + 47 * 47 *(字符的阵列中的位置)例如:输入BA1。总现在是(47 * 47 * 10)+(47 * 11)+ 1 = 243508

Now look at the next character left of the previous one and find it's position in the array.TOTAL += 47 * 47 * (the position of the character in the array)Example: Input is BA1. Total is now (47 * 47 * 10) + (47 * 11) + 1 = 243508

等等。

我建议你写一个单元测试,转换成一串基地10号成基47,然后再返回,以确保您的转换code正常工作。

I suggest you write a unit test that converts a bunch of base 10 numbers into base 47 and then back again to make sure your conversion code works properly.

请注意,你再怎么presented在短短的3个数字基地47的6位十进制数: - )

Note how you represented a 6 digit base 10 number in just 3 digits of base 47 :-)

这篇关于COM pressing大数目(或字符串),以较小的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 08:38