hilaloytun
2022-7-11 12:44:56

Hi again, my first question, should I ask my question in other channels, or is it ok to ask here?


spdegabrielle
2022-7-11 12:45:47

Asking here is fine


hilaloytun
2022-7-11 12:46:21

Thanks a lot, Here is my question: For now I’m storing my post contents in txt files, and call them like that:

(struct post (title body)) (define POST1 (post “First Post” (file->string “01-post.txt”))) (define POST2 (post “Second Post” (file->string “02-post.txt”)))

I want to store my content in a csv file, and starting from the 2nd row, each cell at the 5th column will contain one post content. So is it possible to define a specific cell (lets say at 5th col– 2nd row), as “post-body”?


djholtby
2022-7-11 14:41:57

If you have a CSV file then you can read it just using string-split on comma, if you don’t have to worry about the body itself containing commas. That seems unlikely though? The csv-reading module has readers that can handle quoted cells and/or escaped commas.

Using csv->list will give you a list of lists of strings, so to get the 5th col, 2nd row you’d just chain 2 list-refs together. (I’d use csv-map on the reader though, and convert each row into a post that way)


ben.knoble
2022-7-11 14:43:50

Definitely don’t string-split CSVs unless you are guaranteed to never have commas, which seems vanishingly unlikely. It’s too easy to introduce a comma and not know the program needs updated, and then confusion ensues (at best). (That said, I’m guilty of processing CSVs with Awk where I knew it was safe; these were usually one-time tasks though.)


djholtby
2022-7-11 14:45:34

“Question titles won’t have commas in them” assumed the person about to discover their grading script doesn’t work


hilaloytun
2022-7-11 15:09:08

Thank you very much. I am new to this stuff; so knowing that it is doable is a good start for me, and it doesn’t seem too complicated, but I’ll see… Thanks again.