Read CSV file as txt, char by char

Tiwaz
Member Posts: 98
Hi guys,
I have a CSV file that looks something like this
23;tst;;;12;TEST;2;......
So, my delimiter is ;
Using excel buffer is not an option so I need to read each line of this txt file char by char and write data to some tables because each line has cca 2500 characters so I cannot simply read whole line at once, as one string.
This is in NAV 2009 R2.
Does anyone have any suggestions how to accomplish this?
THanks!
I have a CSV file that looks something like this
23;tst;;;12;TEST;2;......
So, my delimiter is ;
Using excel buffer is not an option so I need to read each line of this txt file char by char and write data to some tables because each line has cca 2500 characters so I cannot simply read whole line at once, as one string.
This is in NAV 2009 R2.
Does anyone have any suggestions how to accomplish this?
THanks!
0
Answers
-
1. You can use a dataport, setting the field delimiter to ; (that will work if you have some sensible record delimiter, new line or smth)
2. You could load the file into bigText using streams, and parse it from there
3. you can read it character by characted using streams too
The dataport will do for you column parsing, while reading the file in code will require you to build some parser to extract columns.
If you decide not to use ther dataport, then loading the file all in one go into BigText will be much much quicker that reading it char by char, but parsing it might be a bit more tricky.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Thank you for your aswer @Slawek_Guzek
I think I'd go with char by char reading.
How can I do it?
I guess, something like
file.READ(CharVar);
but I'm kinda stuck on what to do next...
0 -
This is from NAV 2009 Help:
FileTest.OPEN('c:\XMLDocs\NewTest.txt'); FileTest.CREATEINSTREAM(StreamInTest); // Starting a loop WHILE NOT (StreamInTest.EOS) DO BEGIN Int := StreamInTest.READTEXT(Txt,100); MESSAGE(Txt + '\Size: ' + FORMAT(Int)); END; FileTest.CLOSE();
The above reads the file into Txt var in 100 character long chunks. Use it as your starting point.Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions