News:

  • October 17, 2026, 07:08:10 PM

Login with username, password and session length

Author Topic: Parsing of Text String  (Read 7944 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Parsing of Text String
« on: March 31, 2021, 08:46:41 AM »
Is there a built in function that will parse a text string with known delimiters? Example:

I'm reading TCP data in using STREAMIN. This data is returned to SS0 in the format: 34.12;No;Yes;56.78;True. I want to break out each element and store in a separate string, 34.12->SS20, No->SS21, Yes->SS22, 56.78->SS23, True->SS24. Is there a built in function to do this or does this have be done with a loop?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Parsing of Text String
« Reply #1 on: March 31, 2021, 02:00:31 PM »
See this example project. 
https://forum.hosteng.com/index.php?topic=3303.0

There is a 2nd phase of the tokenizer that parses the data as REALs, so you will definitely need to tweak that 2nd pass code.

It uses a comma as the token delimter.  Just change the code to look for a semicolon.

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Parsing of Text String
« Reply #2 on: April 01, 2021, 10:01:29 AM »
Thanks Franji. Another related question. If I get a string returned, and for example, the string is "ERROR", in this case I would like to set a bit indicating that I'm receiving "ERROR". Is there a function or easy way to set bits/values from an ASCII string?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Parsing of Text String
« Reply #3 on: April 01, 2021, 10:28:36 AM »
STRCMP - String Compare

It supports Less Than, Equal To, and/or Greater Than (you would use just Equal To)
and it supports Case Sensitivity option, e.g. does "Error" match "ERROR" or not?