separate string (tab delimited)
julkifli33
Member Posts: 1,100
hi all...
i have a txt file, which can be read by ";" delimited
how to differentiate the file... if the delimited using TAB?
thanks
i have a txt file, which can be read by ";" delimited
SFile.READ(vString); PosCode:=STRPOS(vString,';'); vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode);
how to differentiate the file... if the delimited using TAB?
thanks
0
Comments
-
Hi,
have you tried the following?
Define a variable called TAB of Type Char
Assign a value with code like this: TAB := 9;
Then reuse your code like this:
SFile.READ(vString);
PosCode:=STRPOS(vString,FORMAT(TAB));
vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1));
vString:=DELSTR(vString,1,STRLEN(vStringTransaction) + STRLEN(FORMAT(TAB)));0 -
i tried that before
but maybe because the delchr --> posode-1
there is an error message like this0 -
If you read from a file with TEXMODE=TRUE, tabs will be converted to spaces with tab stops at position 9, 17, 25... Therefore, you will not find any tab characters anymore. Instead, use InStream.READTEXT and a field separator string according to Maximus's suggestion.
Furthermore, you should guard COPYSTR and DELSTR against the case where STRPOS did not find a field separator (i.e. PosCode=0).
At last, I believe FORMAT without additional parameters does not do anything useful in the construction FORMAT(COPYSTR(....1 -
hi vaprog,
i triedSFile.READ(vString); PosCode := STRPOS(vString,FORMAT(Tab)); vStringTransaction := COPYSTR(vString,1,PosCode); MESSAGE('%1 - %2',PosCode,vStringTransaction);but the poscode still 0
any clue?0 -
hi julkifli33,
I created a text file with three "TAB" characters and tried to read it and it is able to recognise the TAB correctly. Pls try the below code.
//FileStream InStream
//FileTest File
//txt Text 250
//tabchar char
tabchar := 9;
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
IF FORMAT(txt) = FORMAT(tabchar) THEN
MESSAGE('yes');
END;
FileTest.CLOSE();
Best Regards,
MMV0 -
Have you read my post?julkifli33 wrote:any clue?vaprog wrote:use InStream.READTEXT
See MMV's code for reading and looping, then use your code within the loop.
You can safely read a full line of text, as long as you can guarantee that each and every line fits into your text variable. Else you need to read the line in chunks, but this is not much different from reading from a file, only more flexible with streams.0 -
MMV wrote:hi julkifli33,
I created a text file with three "TAB" characters and tried to read it and it is able to recognise the TAB correctly. Pls try the below code.
//FileStream InStream
//FileTest File
//txt Text 250
//tabchar char
tabchar := 9;
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
IF FORMAT(txt) = FORMAT(tabchar) THEN
MESSAGE('yes');
END;
FileTest.CLOSE();
Best Regards,
MMV
Hi MMV,
i just curious how to make this happen
Data :CUST001 ITEM001 8
CUST001 ITEM002 2
CUST001 ITEM003 10
so it will prompt message word by word
-->
first CUST001, and then ITEM001 and then 8.... and then CUST001.... and so on
how to get the word as TAB Delimited as a separator0 -
//FileStream InStream
//FileTest File
//txt Text 250
//tabchar Char
//WholeText Text 1024
//nextPOS Integer
//tempChar Char
//LineFeed Char
//CarriageReturn Char
tabchar := 9;
nextPOS := 0;
LineFeed := 10;
CarriageReturn := 13;
FileTest.OPEN('C:\Users\MMV\Documents\MMV\Misc\tabdelimited2.txt');
FileTest.CREATEINSTREAM(FileStream);
WHILE NOT (FileStream.EOS()) DO
BEGIN
FileStream.READTEXT(txt,1);
FileTest.SEEK(nextPOS);
FileTest.READ(tempChar);
nextPOS += 1;
IF tempChar IN [tabchar,LineFeed,CarriageReturn] THEN BEGIN
MESSAGE('Whole Text %1',WholeText);
WholeText := '';
IF tempChar IN [LineFeed,CarriageReturn] THEN
nextPOS += 1;
END ELSE
WholeText += txt;
END;
FileTest.CLOSE();
Though the above code is a round about mechanism, it works well based on the data you have mentioned in the post (only TAB delimited).0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 328 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

