Axapta:强制容器整数存储为字符串
有没有办法强制容器将所有值存储为字符串?我使用 str2con 来将文本字符串拆分到容器中。 每当出现仅包含数字的字段时,它都会存储为 int,这不是一个大问题。一个大问题是当数字字符串超过整数大小并且数字变得不同时。
考虑以下字符串:
"Text1,Text2" Container becomes: str "Text1", str "Text2"
"1111111111,Text" Container becomes: int 1111111111, str "Text"
"8888888888,Text" Container becomes: int -961633963, str "Text" (THIS IS BAD)
对于如何解决这个问题有什么建议吗?
谢谢
Is there a way to force a container to store all values as strings? I am using str2con in order to split text strings into containers.
Any time a field with numbers only comes up, it is stored as an int, which isn't a huge problem. What IS a big problem is when the string of numbers exceeds the integer size and the number becomes something different.
Consider the following strings:
"Text1,Text2" Container becomes: str "Text1", str "Text2"
"1111111111,Text" Container becomes: int 1111111111, str "Text"
"8888888888,Text" Container becomes: int -961633963, str "Text" (THIS IS BAD)
Any suggestions for how to get around this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过查看 Global.str2con 方法来了解 Microsoft 是如何实现 str2con 的。要阻止该方法将整数添加到容器中,请复制该方法,然后注释掉 add2Ret 子函数中检查字符串是否仅为数字的三行。您可能不想修改现有的 str2con 函数,因为系统的其他部分可能依赖于调用此方法时实际为整数的整数。
或者,您可以添加更复杂的逻辑来检查字符串的长度,并且仅在字符串可能适合整数时才使用 str2int。
You can see how Microsoft implemented str2con by looking at the Global.str2con method. To keep the method from adding integers to a container, make a copy of the method and just comment out the three lines in the add2Ret sub function that check if the string is only digits. You probably don't want to modify the existing str2con function as other parts of the system may depend on integers actually being integers when calling this method.
Or you could add more complicated logic to check the length of the string and only use str2int if the string could possible fit into an integer.
这是替代实现:
Here is alternative implementation:
全局::str2con_RU()
我用过几次,相信大多数环境都有这个方法。
Global::str2con_RU()
I have used this some times, I believe most environments have this method.