Parse space delimited string


I am using PAC control for my project, I have a serial device, that returns a Space delimited string, with multiple variables,

I dont want to use the unpack String, or Get Substring commands, since the length of the string will vary depending on the actual value, for example:

String: “E S S +100.0 200 1520 0” - Could be one String returned
String: “E S s +1245.2 1000 0 0” - Could be the second value.

Could you please advice a simple approach to separate the values into individual strings/integers?


The below will take your input (sInput) and separate by your delimiter (nDelimiter) and store into a string table (stParsed). You can then do what you want with the individual indexes of the string table. It also checks the bounds of your output string table and will stop if the table is full.

This could be made into a subroutine if you need to use it in multiple places in your project.

nParseIndex = 0;
nTableIndex = 0;
nDelimiter = ' ';
//Clear table
MoveToStrTableElements("", 0, GetLengthOfTable(stParsed)-1, stParsed);


  nPosition = FindCharacterInString(nDelimiter, nParseIndex, sInput);
  if(nPosition >= 0) then
    GetSubstring(sInput, nParseIndex, nPosition - nParseIndex, sTemp);
    nParseIndex = nPosition + 1;
    //get end of string
    GetSubstring(sInput, nParseIndex, GetStringLength(sInput) - nParseIndex, sTemp);

  stParsed[nTableIndex] = sTemp;

until(nPosition < 0 or nTableIndex >= GetLengthOfTable(stParsed));
1 Like

Thank you Philip, it worked perfect!