Post Reply 
CSV File Splitter
04-30-2021, 10:12 PM
Post: #1
CSV File Splitter
I needed a program to split a CSV file at each line feed character after loading the file into the Emu48. The CSV file contains local coordinates and descriptions of a fictitious piece of land. The point file is a list of strings containing that information. The integer in the first position of the list represents the number of available positions.

CSV @ Comma-Separated Values file

"1,5000,5000,SW COR■
2,5300,5000,NW COR■
3,5300,5400,NE COR■
4,5000,5400,SE COR"

File @ Point file

{ 4 "" "" "" "" }

FIN @ 240.5 bytes, # 6054h checksum

DUP SIZE 10 CHR 1 \->

@ numpoints - local variable for size of list.
@ csv - local variable for CSV file.
@ size - local variable for size of CSV file. Represents end of file.
@ char - local variable for line feed character.
@ start - local variable for start of substring.

numpoints csv size
char start
\<< MEM DROP 1 @ MEM performs garbage collection.
START csv start
size SUB DUP char

@ Remove substring if line feed character is in string.
\<< DUP 'start'
STO+ 2 - 1 SWAP SUB @ 'start' is moved ahead after each iteration.
\>> IFT

numpoints \->LIST

Any suggestions to improve the code would be greatly appreciated!
Find all posts by this user
Quote this message in a reply
Post Reply 

User(s) browsing this thread: 1 Guest(s)