twincat 2-将字符划分为一系列字符串

发布于 2025-02-12 19:15:16 字数 227 浏览 0 评论 0原文

我正在使用Twincat2进行旧项目,并从TCP连接中获得一系列字符。

示例刺痛是这样的:cmd,011,132654,38201,ABC,23

我需要将其分为单字符串。因此,基本上是一系列字符串,其中MyArray [0]为CMD,[1]是011等。

我无法弄清楚如何做到这一点。 TC3具有拆分函数,但是如何在结构化文本中在TC2中完成这件事?

谢谢

I am using Twincat2 for an old project, and get a array of chars from a TCP connection.

a sample sting is this: CMD,011,132654,38201,ABC,23

I would need to split this into single strings. So basically an array of strings, where myarray[0] is CMD, [1] is 011 etc..

I cannot figure out how to do this. TC3 has a split function, but how can this be done in TC2 in structured text?

Thank you

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

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

发布评论

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

评论(1

野却迷人 2025-02-19 19:15:16

我从未使用过TC2,但这是我要解决问题的方法:

  1. 查找第一个使用查找

位置:= find(samplestring,',');

  1. 将字符分配到此位置,直至使用

?采样,位置1);

  1. 从初始字符串中删除第一个部分字符串和,使用 delete

samplestring:= delete(samplestring,位置,1);

  1. 重复直到在初始字符串中找到,然后将剩余的内容分配给数组的最后一个元素

I have never used TC2, but here is how I would approach the problem:

  1. Find position of the first , using FIND

position := FIND(sampleString, ',');

  1. Assign characters up to this position to first string in the array using LEFT

myArray[0] := LEFT(sampleString, position-1);

  1. Delete first partial string and , from the initial string using DELETE

sampleString := DELETE(sampleString, position, 1);

  1. Repeat until no , is found in the initial string, then assign what remains to the last element of the array
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文