how to parse a read text file

Login to reply to this topic.
Mon, 2008-07-21 08:18
Joined: 2008-03-14
Forum posts: 12

hi all..

am a newbie to symbian,.. Please help to solve the following :
File 1.txt has the contents as below
R1333.003\n1292005

I need to get R1333.003 and 1292005 as separate terms,

am able to read the file and copy the contents to TBuf8<64> buf
using User::LeaveIfError(file.Read(buf));
How should i procced to parse the file and do manupulations only with 1st term or 2nd term

thanks
ksv


Mon, 2008-07-21 10:49
Joined: 2008-06-20
Forum posts: 5
Re: how to parse a read text file

I am also a newbie to Symbian. You can try with the following code.

_LIT(KMyFile,"C:\\temp\\a.txt"); // change with your file name

RFile tempFile;
RFs fs;
User::LeaveIfError( fs.Connect() );
CleanupClosePushL( fs );

TInt err=tempFile.Open(fs, KMyFile, EFileShareExclusive | EFileWrite);

if (err==KErrNotFound) // file does not exist - create it

{
User::LeaveIfError( tempFile.Create( fs, KMyFile, EFileShareExclusive | EFileWrite));
// Write to current file position: start of file
_LIT8(KWriteBuf,"R1333.003"); // write R1333.003 to file
tempFile.Write(KWriteBuf);
}
CleanupClosePushL(tempFile);

TBuf8<6> readBuf1;
tempFile.Read(0,readBuf1); // reads from the first position in file

TBuf<10> buf;
buf.Copy(readBuf1);

Now you have the value R1333.003 in buf.

Thanks
Justin

Mon, 2008-07-21 14:11
Joined: 2007-09-24
Forum posts: 88
Re: how to parse a read text file

Hi KIRAN
Suppose you have copied the content of the file in TBuf8<64> fileContent ;
Now you need to use Find() Method to get the location of "\n" ,

TInt locationInBuf = fileContent .Find(_L8("\n"));
TBuf8<50> firstFileString ;
TBuf8<50> secondFileString ;
firstFileString .Copy(fileContent .Mid(0,locationInBuf )) ;
secondFileString .Copy(secondFileString .Mid(locationInBuf +2,fileContent .Length() -(locationInBuf +2) )) ;

try with above code

Thanks and Regard
Praveen Kumar Sharma

Tue, 2008-07-22 06:30
Joined: 2008-03-14
Forum posts: 12
Re: how to parse a read text file

@Praveen

Hi Praveen
thanks, for the Info... Will try the code...

Regards,
KIRAN

  • Login to reply to this topic.