News:

  • May 14, 2026, 07:21:14 PM

Login with username, password and session length

Author Topic: Trimming junk from a string  (Read 13521 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Trimming junk from a string
« 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.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: Trimming junk from a string
« Reply #1 on: February 02, 2026, 03:48:45 PM »
         "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).

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Trimming junk from a string
« Reply #2 on: February 02, 2026, 05:33:30 PM »
Ok.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: Trimming junk from a string
« Reply #3 on: February 03, 2026, 11:33:52 AM »
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


franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: Trimming junk from a string
« Reply #4 on: February 03, 2026, 11:47:03 AM »
Look at Alarm1SS1 in the JSON Pretty Print tool (Debug->JSON Pretty Print).

Turn on the COLOR CODED NESTING checkbox


franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: Trimming junk from a string
« Reply #5 on: February 03, 2026, 11:51:52 AM »
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.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Trimming junk from a string
« Reply #6 on: February 04, 2026, 08:51:38 AM »
Ok, now I get it, I need to do an additional parsing operation. Thanks.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: Trimming junk from a string
« Reply #7 on: February 04, 2026, 09:53:22 AM »
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?