且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#压缩字母数字字符串

更新时间:2023-02-19 12:40:15

很难说做到这一点就行了"-我们实际上没有足够的信息.
如果ERP代码接受任何字符,则相当容易-字母数字只有26 + 26 + 10个字符,因此将2个字母数字压缩为1个字符(或将4个字母压缩为1个字符是相当容易的)完整的八位字符).但是,即使那样,您也不能将35个字母数字组合为12个字符(除非您可以使用完整的8位).如果您的产品代码仅为A-Z,即0-9,则可以将3.5个字符压缩为7位,这意味着它可以将35个字符压缩到您的12个字符中.
但是,它取决于您的ERP系统以及它可以接受的有效字符-如果它不能接受除AZ,az,0-9以外的任何内容,那么可用的压缩就很小了,您需要找到另一个系统. br/>
你考虑过翻译表吗? 12个字符可以在AZ,AZ,0-9范围内保存4.7E18个不同的值,我非常怀疑您的客户拥有更多的产品!
It is difficult to say "do this and it''ll work" - we don''t really have enough information.
If the ERP code accepted any character then it is reasonably easy - alphanumeric is only 26+26+10 characters, so it''s fairly easy to compress 2 alphanumeric''s into 1 character (or 4 into 1 if you can use the full eight bit characters). However, even then, you can''t fit 35 alphanumerics into 12 characters (unless you can use the full eight bits). If your product code is only A-Z, 0-9 then it could be compressed 3.5 characters to 7 bits, which would mean it could fit 35 characters into your 12.
However, it is dependant on your ERP system and what it can accept as a valid character - if it can''t accept anything except A-Z, a-z, 0-9 then the available compression is minuscule and you need to find another system.

Have you considered a translation table? 12 characters can hold 4.7E18 different values in the range A-Z, a-z, 0-9 and I seriously doubt that your customer has more products than that!