Importing Text from a TAB separated file

Mrinmay
Member Posts: 74
Hi Exparts,
I want to import some data from a file Which is TAB separated. I have written a code like below:
File1.TEXTMODE := True;
File1.Open(path);
File1.Read(String);
Cha := 9;
Pos := STRPOS(String1,FORMAT(Cha));
String2 := STRSUBSTNO(String1,1,Pos-1);
MESSAGE(String2);
But here value before first TAB is not coming.
If TextMode is False then all the line in the text coming as a single string .
Please help me how to separate a string with TAB separator if the file TEXTMODE is true.
Regards,
Mrinmay.
I want to import some data from a file Which is TAB separated. I have written a code like below:
File1.TEXTMODE := True;
File1.Open(path);
File1.Read(String);
Cha := 9;
Pos := STRPOS(String1,FORMAT(Cha));
String2 := STRSUBSTNO(String1,1,Pos-1);
MESSAGE(String2);
But here value before first TAB is not coming.
If TextMode is False then all the line in the text coming as a single string .
Please help me how to separate a string with TAB separator if the file TEXTMODE is true.
Regards,
Mrinmay.
0
Comments
-
any particular reason you're not using a dataport?0
-
I am changing those Dataport into report so that we can run it from RTC. We can use XMLport also. Anyway got the solution :
TestFile1.TEXTMODE := TRUE;
TestFile1.OPEN(Path);
TestFile1.CREATEINSTREAM(InStream1);
WHILE NOT InStream1.EOS DO BEGIN
InStream1.READTEXT(String1,250);
Cha := 9;
String2 := CONVERTSTR(String1 ,FORMAT(Cha),',');
END;
Now we can break the string depending on ','. Or we can separate there itself.
Thank you everybody.0 -
There were three problems in your initial code snippet:
- You read String instead of String1
- You need to use COPYSTR to extract the field, not STRSUBSTNO
- READ from a TEXTMODE file converts tabs to spaces. You need to use CREATEINSTREAM and then READTEXT from the stream.
You do not need the CONVETRSTRING in your second code snippet. In fact this causes problems if there are commas in the data. STRPOS with the tab character formated as you did works well.Mrinmay wrote:Now we can break the string depending on ','. Or we can separate there itself.0
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