在 C# 中按特定值递增字母数字 ID 的最佳方法是什么?
在 C# 中按特定值递增字母数字 ID 的最佳方法是什么?
例如:
我们已经 345FAS310E575896325SA 并且我们将增加 123 ,因此我们得到结果:345FAS310E575896325SA123
或者我们< 345FAS310E575896325SA123并增加 234 ,结果应该是 345FAS310E575896325SA357
什么是使其工作的“最便宜”方法?
What is a best way to increment alphanumeric ID by certain value in C#?
For example:
We've 345FAS310E575896325SA and we're going to increment by 123 , so we have as result: 345FAS310E575896325SA123
Or we've 345FAS310E575896325SA123 and increments by 234 , and result should be 345FAS310E575896325SA357
What is a "cheapest" way to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我的算法:
This is my algorithm:
每个人都遇到的问题是您的字母数字值实际上没有任何意义。
当您给出示例时,您只是在末尾添加数字并递增这些数字,您并没有真正向我们提供有关字母代表什么的任何信息。
为了能够增加这样的值,我们需要知道字母的值是什么,一个很好的例子是十六进制,0 - 9 A - F,所以如果你说将十六进制值 09 加 1,你会得到0A 并将 0F 加 1 得到 10
我知道这不是答案,但在您向我们提供一些关于您希望通过此实现的目标的真实信息之前,我们无法真正给出答案。也许还可以告诉我们您用它做什么/为什么使用字母数字等?
The problem everyone is having here is that your Alphanumeric value doesnt really mean anything.
When you give your examples you are just adding numbers onto the end and incrementing those, you havent really given us any information about what the letters represent.
To be able to increment a value like this we need to know what the value of the letters are, a good example would be HEX, 0 - 9 A - F so if you were to say increment the HEX value 09 by 1 you would get 0A and incrementing 0F by 1 gives 10
I know this isnt an answer but until you give us some real info on what you are aiming to achieve with this we cant really give an answer. Also maybe tell us what you are using this for / why AlphaNumeric etc?
通过查看您的示例,我将其解释为:
如果没有 id 后缀,则应附加一个。否则,ID 应递增。
By looking at your examples, I interpret it like this:
If no ids are suffixed, one should be appended. Else, the ID should be incremented.
子字符串方法?在您传入要增加的数字的地方,它会获取增加值的子字符串并将它们加在一起?
当增量超过 99 时会发生什么?
它只是将 100 添加到字母数字 ID 的末尾吗?
另外,字母数字 ID 的其余部分会保持不变吗?即:
843342D4343DA123D 10
843342D4343DA123D 20
A Substring method? Where you pass in the number you wish to increment by, it will get the substring of the incremented values and add them together?
What happens when the increment goes over 99?
Does it just append 100 to the end of the alphanumeric ID?
Also will the rest of the alphanumberic ID stay the same? i.e:
843342D4343DA123D 10
843342D4343DA123D 20