Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

How long can a WSTRING be in CodeSys V3?

Volvo742
2018-03-21
2020-06-10
  • Volvo742

    Volvo742 - 2018-03-21

    Hi!

    How long can a WSTRING be in Codesys V3 if I concat it with Standard64 library?
    Is it maximum 1000 characthers or does it depends how many memory I have left to use?

    So I can concat a array for 1000 elements to one WSTRING if each element has e.g 5 characters?

    Best regards

     
  • e.kislov

    e.kislov - 2018-03-21

    Volvo742 hat geschrieben:
    Hi!
    How long can a WSTRING be in Codesys V3 if I concat it with Standard64 library?

    255 chars

    You can use other methods to do it (pointers, SysMem, etc.)

     
  • Volvo742

    Volvo742 - 2018-03-21

    e.kislov hat geschrieben:
    255 chars

    But isn't that STRING ?

    Zitat:
    As a rule, CODESYS does not limit the string length; however, If a variable is initialized with a string that is too long for the data type, then CODESYS truncates the string accordingly from the right.

    https://help.codesys.com/api-content/2/ ... -3s-string m

     
  • e.kislov

    e.kislov - 2018-03-21

    "String functions" are all functions which used for any strings. No matter STRING type (ASCII-based charset) or WSTRING (Unicode/UCS2) - only 255 chars supported in Standard/Standard64 library.

     
  • Volvo742

    Volvo742 - 2018-03-21

    e.kislov hat geschrieben:
    "String functions" are all functions which used for any strings. No matter STRING type (ASCII-based charset) or WSTRING (Unicode/UCS2) - only 255 chars supprorted in Standard/Standard64 library.

    Ok. So there is no idea to have a longer string?

    Who set the 255 limit? That's very bad.

     
  • e.kislov

    e.kislov - 2018-03-21

    As I say before - pointers, SysMem...
    So you need to use memory manipulation.

     
  • Volvo742

    Volvo742 - 2018-03-21

    Edwin Schwellinger hat geschrieben:
    Hi,
    would recomended to use StringUtils.library!
    BR
    Edwin

    Thanks! So there is no limit for StringUtils library?

     
  • Volvo742

    Volvo742 - 2018-03-21

    I included the library StringUtils, but still, the maximum string length is 80 chars.

    IMG: Capture.PNG

    IMG: Capture.PNG

     
  • Comingback4u

    Comingback4u - 2018-03-21

    You need to use the function calls in Stu and not the Standard library. For example:

    Stu.Standard.LEN should really be Stu.StrLenW
    Stu.Standard.CONCAT should really be Stu.StrConcatW

    If you look at the data type of Stu.Standard.LEN/CONCAT it is looking for a string input which has the 255 character max. This means anything you pass it automatically gets truncated if it is larger than 255. The Stu.StrLenW input is looking at a pointer which it will iterate through until it finds the terminating zero character. This gives it a way to not be size restricted.

    So for your code try

    StringLength := Stu.StrLenW(ADR(TomString));
    

    StringLength needs to be DINT. This is like how Edwin did it but he used WSTRING instead of STRING so different function calls are needed.

     
  • jtebokkel

    jtebokkel - 2020-06-10
     

    Last edit: jtebokkel 2020-06-10

Log in to post a comment.