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.
0
Comments
http://www.BiloBeauty.com
http://www.autismspeaks.org
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.
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.
This leads me to think you attempt to use SELECTSTR to split the line into fields. However, you should not use SELECTSTR for unknown data as SELECTSTR requires all fieled values to be distinct after they were capitalised, and requires the last field to be non-empty. (See C/SIDE help on SELECTSTR).