我需要连接几个字符串

时间:2015-05-23 01:43:59

标签: iec61131-3 structured-text

我是结构化文本的新手,我想知道如何连接几个字符串。最干净的方式。在这个实例中,我只需要在创建字符串时更改一个变量。我有另一个我需要做的事情2.这个数字可能会增长。这样做的目的是我可以将XML消息发送到HTTP服务器。这是用于记录数据。

在这个例子中,读者变量是一个单词。

Facebook\GraphObject Object

4 个答案:

答案 0 :(得分:0)

我认为您需要在JavaScript中执行此操作。

var replaceDue = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\
  <s:Header>\
    <Action s:mustUnderstand=\"1\"xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/IService/receiveHeartbeat</Action>\
  </s:Header>\
  <s:Body>\
    <receiveHeartbeat xmlns=\"http://tempuri.org/\">\
      <reader>**Word Variable**</reader>\
    </receiveHeartbeat>\
  </s:Body>\
</s:Envelope>";
var wordVariable = "value to replace";
var replaceDone = replaceDue.replace("**Word Variable**", wordVariable);

答案 1 :(得分:0)

我想我找到了解决方案。我不喜欢它。它不是很干净。

Reader_ID: STRING := '0';
msg: STRING(500);
Msg1: STRING(250) := '<s:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><s:Header>';
Msg2: STRING(250) := '<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService/receiveHeartbeat</Action>';
Msg3: STRING := '</s:Header><s:Body><receiveHeartbeat xmlns="http://tempuri.org/"><reader>';
MsgAfter: STRING := '</reader></receiveHeartbeat></s:Body></s:Envelope>';
msg := CONCAT(Msg1,Msg2);
msg := CONCAT(msg,Msg3);
msg := CONCAT(msg,Reader_ID);
msg := CONCAT(msg,MsgAfter);

字符串大小似乎限制为500个字符。因为这一点是要创建一个通过HTTP发送的XML消息。当我的消息不可避免地超过500个字符时会发生什么。我正在使用WagoLibHttp_02库来获取http。

答案 2 :(得分:0)

您可以像这样链接CONCAT函数:
concat3: STRING := CONCAT(CONCAT(str1, str2), str3);
但是,请注意,默认情况下,STRING只有80个字符(字节)长。您可以使用括号指定大小:
concat3: STRING(255) := CONCAT(CONCAT(str1, str2), str3);
但是同样,标准CONCAT函数仅接受并返回长度最多为255个的字符串!

如果您需要长度超过255的字符串,请检查codesys文档中的Working with Strings More Than 255 Characters

答案 3 :(得分:0)

如果您使用的是 Wago,那么您应该可以访问他们的 CONCAT 函数...CONCAT3(),CONCAT4()...CONCAT9()。这比嵌套很多标准的 CONCAT 函数要干净得多

相关问题