how to parse a read text file
| Mon, 2008-07-21 08:18 | |
|
hi all.. am a newbie to symbian,.. Please help to solve the following : 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 thanks |
|






Forum posts: 5
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
Forum posts: 88
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
Forum posts: 12
@Praveen
Hi Praveen
thanks, for the Info... Will try the code...
Regards,
KIRAN