How to parse a file with value pairs
Afficher commentaires plus anciens
Hi was looking for ideas on how to best parse a text file which lines are in the following format
!FIX.BODY=xxxxx|2125=aaaaaa|1067=bbbbb|150=ccccc|329=ddddd|
the line is delimited by a '|' and it represents a value pair with the column name followed by an equal sign = followed by the value.
So in the example above I would like to end up with a table like this
FIX.BODY 2125 1067 150 329
___________________________________________
xxxxx aaaaaa bbbbb ccccc ddddd
3 commentaires
"how to best parse a text file which lines are in the following format"
You use the plural, so the file contains multiple lines: do the lines have the same variable names/numbers, or different ones? Are the number of columns/fields/variables the same on each line, or can they differ?
The simplest would be if you upload a sample file by clicking the paperclip button. Descriptions of files are invariably inadequate compared to actually just getting a sample file, and will delay you actually getting a working solution.
Ruben Ruiloba
le 25 Août 2020
"I can't upload the file as it has confidential data but it would look something like this."
A sample file does not have to contain confidential data in it, because you can write it with random, invented, made up data. However it should include all of the salient features of the actual data files, such as EOL character/s, file encoding (especially if this file is being generated from some other application), representative character strings, number encodings, etc.
Providing a file gives us an agreed reference with which we can test our code.
Not providing a file slows down you getting the solution you want.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!