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 770031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:25:57+00:00 2026-05-14T18:25:57+00:00

I’ve got a text file that arrives at my application as many lines of

  • 0

I’ve got a text file that arrives at my application as many lines of the following form:

<row amount="192.00" store="10" transaction_date="2009-10-22T12:08:49.640"
 comp_name="blah                                            " 
 comp_ref="C65551253E7A4589A54D7CCD468D8AFA" 
 name="Accrington                                                  "/>

and I’d like to turn this ‘row’ into a series of name/value pairs in a given TStringList (there could be dozens of these <row>s in the file, so eventually I will want to iterate through the file breaking each row into name/value pairs in turn).

The problem I’ve got is that the data isn’t obviously delimited (technically, I suppose it’s space delimited). Now if it wasn’t for the fact that some of the values contain leading or trailing spaces, I could probably make a few reasonable assumptions and code something to break a row up based on spaces. But as the values themselves may or may not contain spaces, I don’t see an obvious way to do this. Delphi’ TStringList.CommaText doesn’t help, and I’ve tried playing around with Delimiter but I get caught-out by the spaces inside the values each time.

Does anyone have a clever Delphi technique for turning the sample above into something resembling this? ;

amount="192.00"
store="10"
transaction_date="2009-10-22T12:08:49.640"
comp_name="blah                                            " 
comp_ref="C65551253E7A4589A54D7CCD468D8AFA" 
name="Accrington                                                  "

Unfortunately, as is usually the case with this kind of thing, I don’t have any control over the format of the data to begin with – I can’t go back and ‘make’ it comma delimited at source, for instance. Although I guess I could probably write some code to turn it into comma delimited – would rather find a nice way to work with what I have though.

This would be in Delphi 2007, if it makes any difference.

  • 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-14T18:25:58+00:00Added an answer on May 14, 2026 at 6:25 pm
    procedure RowToStrings(const row: string; list: TStrings);
    var
      i       : integer;
      iDelim  : integer;
      inQuotes: boolean;
    begin
      iDelim := 0;
      inQuotes := false;
      for i := 1 to Length(row) do begin
        if (row[i] = ' ') and (not inQuotes) then begin
          list.Add(Copy(row, iDelim+1, i-iDelim-1));
          iDelim := i;
        end
        else if row[i] = '"' then
          inQuotes := not inQuotes;
      end;
      list.Add(Copy(row, iDelim+1, Length(row)-iDelim));
    end;
    
    procedure TForm37.Test;
    var
      row: string;
    begin
      row := 'amount="192.00" store="10" transaction_date="2009-10-22T12:08:49.640" ' +
             'comp_name="blah                                            " '          +
             'comp_ref="C65551253E7A4589A54D7CCD468D8AFA" '                           +
             'name="Accrington                                                  "';
      RowToStrings(row, ListBox1.Items);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.