Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: PLCwannabe on February 02, 2026, 03:40:37 PM
-
What is the easiest way to trim junk from the back end of a string? I'm able to trim the front end with The Get Sub-String (STRSUB) instruction, but the end is harder to trim because the strings are a variable lenght. eg. { ...current: "All Clear"...} The string always begins with the same 15 characters, but the message varies depending on the current conditions. So right now I end up with
"All Clear"...} and I want to remove the periods and the curly brace at the end.
-
"All Clear"...} and I want to remove the periods and the curly brace at the end.
Show a screen shot of a sample string in Data View in "8 Hex/ASCII" text format.
I am guessing there's CR/LF and something else in there, and you will need to use STRFIND and STRTRUNC, but we need to understand the delimiters (again, probably CR/LF, but need to make sure, hence the Data View screen shot).
-
Ok.
-
It's JSON! IIOT likes JSON records. Do-more PLCs speak JSON!
Basically, you want to do a JSONPARSE for the field "current" whose data is a string (the field names are always in double quotes, but the data in a JSON record can be numeric or string, "current" is a string)
See the attached screen shot.
Try it and turn on Ladder Status to crack the return results code properly. The details on a successful parse is in the Help Topic for JSONPARSE DMD0454
-
Look at Alarm1SS1 in the JSON Pretty Print tool (Debug->JSON Pretty Print).
Turn on the COLOR CODED NESTING checkbox
-
You may want to do a STRTRIM on the result in SL0 to remove the trailing spaces. I wrote a small program to do your sample and it worked. See the attached screen shot.
-
Ok, now I get it, I need to do an additional parsing operation. Thanks.
-
Ok, now I get it, I need to do an additional parsing operation. Thanks.
I think you just need to replace whatever parsing you have with JSONPARSE (no "additional" parsing necessary). The device is returning a JSON record and Do-more has the JSON parsing algorithm in that instruction. So take the string being read from the device and feed it in JSONPARSE - it handles any/all white space in the input string. Unless there's some other overhead wrapped around the data being returned from your device?