![]() |
Forum Index : Microcontroller and PC projects : formatting csv files
Author | Message | ||||
zeitfest Guru ![]() Joined: 31/07/2019 Location: AustraliaPosts: 551 |
In general, do csv files have formatted field data ? I think the whole point of csv's is convenience without formatting hassles. I have been assuming that csv format just has data as ascii text fields with comma separators, with each field text length arbitrary. So to format each field individually would probably be unrequired complexity, may as well just use a string of text for each field, up to a default length for each datatype. Is that the right track ? |
||||
tgerbic Regular Member ![]() Joined: 25/07/2019 Location: United StatesPosts: 58 |
It is just commas between fields. Simple. Just remember that the data must not have any commas in the text or it will be seen as another separator and offset all the rest of the data by the number of embedded commas. |
||||
Gizmo![]() Admin Group ![]() Joined: 05/06/2004 Location: AustraliaPosts: 5111 |
I use tabs as the delimiter, means you can include commas in your text. If you have a lot of formatted text, you can use double quotes, eg "Apples","Pears","Oranges" If there is a double quote in the text, you can escape it using another double quote. eg "Fred said ""Hi"". ","Jane said ""How are you""." I'm using commas as the delimiter here because a tab isn't visible. Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2458 |
INPUT # finds the comas and assigns the content of each field to a variable. Can be string variables. eg dim a(5) > input a(0),a(1),a(2) ? 5,6,7 > math v_print a() 5.0000, 6.0000, 7.0000, 0.0000, 0.0000, 0.0000 > dim s$(6), d$="sun,mon,tue,wed,thu,fri,sat" > open "days.txt" for append as #3 > ? #3, d$ > close #3 > list "days.txt" sun,mon,tue,wed,thu,fri,sat > > open "days.txt" for input as #3 > input #3, s$(0),s$(1),s$(2),s$(3),s$(4),s$(5),s$(6) > close #3 > for n=0 to 6:? s$(n), :next sun mon tue wed thu fri sat > It's a pity this doesn't work input a() Edited 2025-02-13 12:32 by phil99 |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4920 |
Hi Phil, Pitty you did not name your file "days.csv". That would have matched the topic ![]() Volhout Edited 2025-02-13 17:17 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2458 |
deleted Edited 2025-02-16 17:34 by phil99 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |