从另一个太长的唯一数值创建固定长度的唯一字符串

发布于 2025-01-05 18:49:29 字数 375 浏览 0 评论 0原文

我正在使用 VB .Net 访问 eBay API 并将所有已完成的订单存储在数据库中。然后将该数据库输入专有运输系统,该系统无法处理超过 20 个字符的订单号。 eBay 返回类似 230407279314-680141236013 的订单号,该编号太长。订单号始终为 12 个数字(一个连字符)和 12 个以上的数字。我需要做的是将其(结果可以是字母数字)转换为更短、唯一的订单密钥,与真实的 orderId 一起存储在我的数据库中(以便运输软件可以引用它,而不是实际的订单号) )。 20 个字符限制的原因是所使用的条形码算法。有没有办法在 VB .Net 2010 中实现这一点?这个数字可以是任何唯一的,只要它不存在(即使是一个好的 uniqueid 函数也可以,但我必须查询数据库以确保它不被占用)

I am using VB .Net to access the eBay API and store all completed orders in a database. This database is then fed into a proprietary shipping system, which can not handle an order number larger than 20 characters. eBay returns an order number like so 230407279314-680141236013 which is too long. The order number is always 12 numbers a hyphen and 12 more numbers. What I need to do, is turn this (the result can be alpha numerical) into a shorter, unique order key to store in my database alongside the true orderId (so that this can be referenced by the shipping software instead of the actual order number). The reason for the 20 character limit is the barcode algorithm used. Is there any way to achieve this in VB .Net 2010? This number can be anything unique, so long as it does not exist already (even a good uniqueid function would work, but I would have to query the database to make sure it isn't taken)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有伤那来痛 2025-01-12 18:49:29

实际上,您可以将该数字转换为 20 个字符的字符串。您可以将数字拆分为六位数字。由于每个只需要存储 20 位,因此您可以将它们表示为五位十六进制数:

230407 -> 38407
279314 -> 44312
680141 -> A60CD
236013 -> 399ED

这将给出 20 个字符串:

3840744312A60CD399ED

这样做:

Dim code As String = _
  Int32.Parse(orderNumber.Substring(0, 5)).ToString("x5") + _
  Int32.Parse(orderNumber.Substring(5, 5)).ToString("x5") + _
  Int32.Parse(orderNumber.Substring(11, 5)).ToString("x5") + _
  Int32.Parse(orderNumber.Substring(16, 5)).ToString("x5")

You can actually turn that number into a 20 character string. You can split the numbers into six digit numbers. As each of those only need 20 bits to be stored, you can then represent them as a five digit hexadecimal number:

230407 -> 38407
279314 -> 44312
680141 -> A60CD
236013 -> 399ED

Which would give the 20 character string:

3840744312A60CD399ED

Do it like this:

Dim code As String = _
  Int32.Parse(orderNumber.Substring(0, 5)).ToString("x5") + _
  Int32.Parse(orderNumber.Substring(5, 5)).ToString("x5") + _
  Int32.Parse(orderNumber.Substring(11, 5)).ToString("x5") + _
  Int32.Parse(orderNumber.Substring(16, 5)).ToString("x5")
溺渁∝ 2025-01-12 18:49:29

您可以将其存储为一个唯一的十六进制数字 - 假设您已将 eBay 代码存储为两个字符串:lefstr '-' rightstring。因此,在本例中,左字符串 = '230407279314',右字符串 = '680141236013'。

将它们放入单个字符串并从中检索整数值后,您应该能够将其存储为十六进制字符串: id.toString("x")

id 的长度将不超过 20 个十六进制字符: )

You could store it as one unique hex number - say you've stored the ebay code as two strings: lefstr '-' rightstring. So in this case leftstring = '230407279314' and rightstring = '680141236013'.

once you've put them into a single string and retrieved the integer value from it you should be able to store it as a string in hex: id.toString("x")

the id will be no more than 20 hexadecimal characters long :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文