Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:41 24 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : formatting csv files

Author Message
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 551
Posted: 10:07pm 12 Feb 2025
Copy link to clipboard 
Print this post

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 States
Posts: 58
Posted: 11:06pm 12 Feb 2025
Copy link to clipboard 
Print this post

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: Australia
Posts: 5111
Posted: 11:45pm 12 Feb 2025
Copy link to clipboard 
Print this post

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: Australia
Posts: 2458
Posted: 11:46pm 12 Feb 2025
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 4920
Posted: 07:17am 13 Feb 2025
Copy link to clipboard 
Print this post

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: Australia
Posts: 2458
Posted: 07:30am 16 Feb 2025
Copy link to clipboard 
Print this post

deleted
Edited 2025-02-16 17:34 by phil99
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025