Axapta:强制容器整数存储为字符串

发布于 2024-08-12 04:01:03 字数 409 浏览 3 评论 0原文

有没有办法强制容器将所有值存储为字符串?我使用 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 技术交流群。

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

发布评论

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

评论(3

国际总奸 2024-08-19 04:01:03

您可以通过查看 Global.str2con 方法来了解 Microsoft 是如何实现 str2con 的。要阻止该方法将整数添加到容器中,请复制该方法,然后注释掉 add2Ret 子函数中检查字符串是否仅为数字的三行。您可能不想修改现有的 str2con 函数,因为系统的其他部分可能依赖于调用此方法时实际为整数的整数。

void add2Ret(str _current)
{  
    // v-artemt, 26 Jul 2004, PS#: 1741
 //remove next three lines so only integers will be added as strings not integers
 //   if (match('<:d+>', _current))
 //       ret += str2int(_current);
 //   else
        ret += _current;
}

或者,您可以添加更复杂的逻辑来检查字符串的长度,并且仅在字符串可能适合整数时才使用 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.

void add2Ret(str _current)
{  
    // v-artemt, 26 Jul 2004, PS#: 1741
 //remove next three lines so only integers will be added as strings not integers
 //   if (match('<:d+>', _current))
 //       ret += str2int(_current);
 //   else
        ret += _current;
}

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.

抹茶夏天i‖ 2024-08-19 04:01:03

这是替代实现:

#define.Comma(",")

static container str2con_alt(str _string, str _separator = #Comma, boolean  _ignoreNearSeparator = false)
{
  container con = connull();
  int       pos, oldPos = 1;
  str       tmpStr;

  do
  {
      pos    =  strscan(_string, _separator, pos ? pos + strlen(_separator) : 1, strlen(_string));
      tmpStr =  substr(_string, oldPos, pos ? pos - oldPos : strlen(_string) + 1 - oldPos);

      if (tmpStr || ! _ignoreNearSeparator)
      {
         con += tmpStr;
      }

      oldPos =  pos + strlen(_separator);
  }
  while (pos);

  return con;
}

Here is alternative implementation:

#define.Comma(",")

static container str2con_alt(str _string, str _separator = #Comma, boolean  _ignoreNearSeparator = false)
{
  container con = connull();
  int       pos, oldPos = 1;
  str       tmpStr;

  do
  {
      pos    =  strscan(_string, _separator, pos ? pos + strlen(_separator) : 1, strlen(_string));
      tmpStr =  substr(_string, oldPos, pos ? pos - oldPos : strlen(_string) + 1 - oldPos);

      if (tmpStr || ! _ignoreNearSeparator)
      {
         con += tmpStr;
      }

      oldPos =  pos + strlen(_separator);
  }
  while (pos);

  return con;
}
无法言说的痛 2024-08-19 04:01:03

全局::str2con_RU()
我用过几次,相信大多数环境都有这个方法。

ledgerCon = str2con_RU(ledgerDimStr,#sep);

//或

ledgerCon = Global::str2con_RU(ledgerDimStr,#sep);

Global::str2con_RU()
I have used this some times, I believe most environments have this method.

ledgerCon = str2con_RU(ledgerDimStr,#sep);

//or

ledgerCon = Global::str2con_RU(ledgerDimStr,#sep);

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