I have to read from a text file some field in order to import data. The row is separated from tab character. I tryied to use this code:
[char] TabChar := 9;
[string] Tab := Format(TabChar);
[integer] position := StrPos(NomeFile, NomeFile);
[integer] TabPosition := STRPOS(ImportTextSubtring, Tab); // here TabPosition gets always zero (it does not detect the tab in the string)
Then I get the string until the tab as field and I replace the current long string with one without the last one.
ImportTextSubtring := COPYSTR(ImportTextSubtring, ImportTextStartPos);
The issue is that "STRPOS(ImportTextSubtring, Tab)" does not detect "Tab" character in the text. How can I detect the tab field? Or how can I get the separation of the string using a Tab character? The issue is that I use a function which gets the string using an initial fixed postion and a final fixed position.
But if I use a concatenated string using a Tab character, the "StrPos" functions do work:
Tab := 9;
vtab := FORMAT(Tab);
vtest := 'pippoxx' + vtab + 'pippo';
TabPosition := STRPOS(vtest, vtab); // TabPosition gets 8: right!
MESSAGE('The position is: %1', TabPosition);
0
Comments
try the following:
Tab := ' '; // important to initialize string length to 1
Tab[1] := 9; // store tab into this 1-char-string
Oliver
Attached a text piece in image jpg format showing invisible characters file to be imported. If I write tab character using ALT+[ASII code number], I will get a different character (that is '○'). But showing all characters (also not visible ones) on text file it appears like an arrow, that is a horizontal tab character.
Can you check the attached file please?
In my code 'Tab' variable is a char. I tried using your code, but it does not change anything: STRPOS returs zero.
Anyway thank you. Do you have any further ideas or insights?
You should Try it with textvariable Length =1 and read the file via a Stream
Then you can Check if your Tab is really ASCII 9
Chris
Here is an example that works for me,
More about this method for reading and writing text files on my blog http://www.dynamics.is/?p=1405
Gunnar Gestsson
Microsoft Certified IT Professional
Dynamics NAV MVP
http://www.dynamics.is
http://Objects4NAV.com