Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3938520
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:11:39+00:00 2026-05-20T00:11:39+00:00

So, I am reading from ModBos over serial port and get readings something like

  • 0

So, I am reading from ModBos over serial port and get readings something like the following : '+0020.8+0022.8-00.046-00.002-00.005-001.99+00.000+00.003';

Basically, there will always be 8 floating point readings, preceded by a plus or minus sign, although they may be of varying character length.

What’s the most efficient way to get the values an array of float (or array of string or TSringList)?

I am not certain, but this might be time critical, so efficiency probably has way over elegance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:11:39+00:00Added an answer on May 20, 2026 at 12:11 am

    I would do something like this:

    type
      TFloatArray = array[0..7] of Double;
    
    procedure ParseFloats(const aFloatStr: string;
      var aFloatArray: TFloatArray);
    var
      lPos: Integer;
      lNextPos: Integer;
      lPosPositive: Integer;
      lPosNegative: Integer;
      i: Integer;
      lFormatSettings: TFormatSettings;
    begin
      //do not forget formatsettings, or you will get problems with regional settings
      lFormatSettings.DecimalSeparator := '.';
      lFormatSettings.ThousandSeparator := ',';
      lPos := 1;
      for i := 0 to High(aFloatArray) do
      begin
        lPosPositive := PosEx('+', aFloatStr, lPos + 1);
        lPosNegative := PosEx('-', aFloatStr, lPos + 1);
        if lPosPositive = 0 then
          lNextPos := lPosNegative
        else if lPosNegative = 0 then
          lNextPos := lPosPositive
        else
          lNextPos := Min(lPosPositive, lPosNegative);
        if lNextPos = 0 then
          lNextPos := Length(aFloatStr) + 1;
        aFloatArray[i] := StrToFloat(Copy(aFloatStr, lPos, lNextPos - lPos), lFormatSettings);
        lPos := lNextPos;
      end;
    end;
    
    //call like this
    var
      lFloats: TFloatArray;
    begin
      ParseFloats('+0020.8+0022.8-00.046-00.002-00.005-001.99+00.000+00.003', lFloats);
    end;
    

    Because there are always 8 float values, a fixed array of 8 doubles is enough. I kept string manipulation to a minimum, only once per floating point value a string is copied. Important is the TFormatSettings, otherwise you will get errors on systems where the decimal separator is not a dot (like mine).

    There is no exception handling here, I expect a string with 8 floating point values, nothing more, nothing less.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading from serial port using string messaga = _serialPort.ReadLine(); When i Console.WriteLine(messaga);
While reading from serial port I am using serialport.read(xyz,0,4) where xyz is a byte
In VBA I'm reading from a text file (it has tags like an xml
I'm reading from a binary data file which is written by invoking the following
I am reading from a file with data like this: {day :Monday, alarm:on, kids:School
After some reading from this tutorial , I have the following partly working code:
While reading from Bruce Eckel's Thinking in C++ about namespaces, I encountered the following
while reading from BRUCE ECKEL'S THINKING IN C++..i came across the following text In
So im reading from a file like so. f = open(log.txt, 'w+r') f.read() So
I'm reading from a boost::asio::ip::udp::socket like this: using boost::asio::ip::udp; // ... char recv_buf[128]; udp::endpoint

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.