×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Regular Contributor
    Join Date
    Jan 2012
    Posts
    139

    [moved] getting substring from text file

    Hi All,

    I have text file and its data as follow:
    aaa#bbb#ccc#ddd#
    aa#bb#cc#ddddd#...
    now I want to take substring upto separator#.
    my code as follows:

    TChar ch;

    TBuf8<50> token;

    while((ch = lex.Get()) != 0 )
    {
    while ((ch = lex.Peek()) != '#')
    lex.Inc();
    token.Copy(lex.MarkedToken());
    lex.Inc();
    lex.Mark();
    }

    But it doesnt work
    is there anyother way to do it???
    Kindly help me
    Thanks,
    Nishaant

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: getting substring from text file

    you could use the Find function provide by the TBuf8 to find the start position of the separator, and then use Left/Mid/Right functions to get substrings out from it.

  3. #3
    Regular Contributor
    Join Date
    Jan 2012
    Posts
    139

    Re: getting substring from text file

    Thanks symbianyucca for reply
    can u elaborate this please....
    thanks

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: getting substring from text file

    here's one older thread on the topic: http://www.developer.nokia.com/Commu...part-of-string Also you could check API docs, for example open http://library.developer.nokia.com/ and search for TDes which is the base class for TBuf

  5. #5
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,006

    Re: getting substring from text file

    Quote Originally Posted by nishantanindya View Post
    Hi All,

    I have text file and its data as follow:
    aaa#bbb#ccc#ddd#
    aa#bb#cc#ddddd#...
    now I want to take substring upto separator#.
    my code as follows:

    TChar ch;

    TBuf8<50> token;

    while((ch = lex.Get()) != 0 )
    {
    while ((ch = lex.Peek()) != '#')
    lex.Inc();
    token.Copy(lex.MarkedToken());
    lex.Inc();
    lex.Mark();
    }

    But it doesnt work
    is there anyother way to do it???
    Kindly help me
    Thanks,
    Nishaant
    Btw , can you elaborate what is not working, if i go by this article : http://www.developer.nokia.com/Commu...arator_in_TLex , then you have done exactly like that so it should be working, except the case if your requirement is something else(do you want aaa, bbb etc to be copied/appended one by one or what?)

  6. #6
    Regular Contributor
    Join Date
    Jan 2012
    Posts
    139

    Re: getting substring from text file

    I have my string in TBuf8<500> Demobuf;
    TInt pos=0;
    TBuf8<256> FileData8;
    // TBuf16<500> FileData16;//0xEF24C10A
    _LIT(KFileSpec,"C:\\System\\test.txt");
    // TBuf8<KBufSize> Demobuf;
    TBuf8<500> Demobuf;
    TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileSpec);
    //This path is mapped as: C:\Symbian\8.0a\S60_2nd_FP2\epoc32\wins\c\System\Test.txt
    RFs iFs;
    iFs.Connect();
    RFile iFile;

    if ((KErrNone != err) && (KErrAlreadyExists != err))
    {
    return;
    }
    TInt iErr=iFile.Open(iFs,KFileSpec,EFileRead);
    if(iErr==KErrNone)
    {
    iFile.Seek(ESeekStart, pos);
    iFile.Read(FileData8);
    Demobuf.Copy(FileData8);
    iFile.Close();
    }
    iFs.Close();
    TInt pos1 = Demobuf.Find(_L("#"));


    But I am getting error
    Multiple markers at this line
    - 'TDesC8::Find(const unsigned char *, int)
    const' (non-static)
    - 'TDesC8::Find(const TDesC8 &) const' (non-static)

  7. #7
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,006

    Re: getting substring from text file

    Find(_L8("#"))

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: getting substring from text file

    Or, for single characters: Locate('#') is faster.

  9. #9
    Regular Contributor
    Join Date
    Jan 2012
    Posts
    139

    Re: getting substring from text file

    hmmmm it is working both locate and L8
    now how can i store substring upto # separator in other variable
    like TBuf8 token;
    token.copy(pos1)????
    Please tell me..

  10. #10
    Regular Contributor
    Join Date
    Jan 2012
    Posts
    139

    Re: getting substring from text file

    or how can i store substring in array..???

  11. #11
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: getting substring from text file

    CDesCArrayFlat would be one option, also you could use RPointerArray with HBufC8's, then you could use the AllocL from the TDes as well for constructing the objects.

  12. #12
    Regular Contributor
    Join Date
    Jan 2012
    Posts
    139

    Re: getting substring from text file

    This is not working..
    while(Demobuf.MaxLength())
    {
    TInt loc = Demobuf.Find(_L8('#'));
    TBuf8<50> token;
    token.Copy(Demobuf);
    }

  13. #13
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,006

    Re: getting substring from text file

    Something similar is described/discussed here : http://www.developer.nokia.com/Commu...ght=Find%28_L8

  14. #14
    Regular Contributor
    Join Date
    Jan 2012
    Posts
    139

    Re: getting substring from text file

    if(iErr==KErrNone)
    {
    iFile.Seek(ESeekStart, pos);
    iFile.Read(FileData8);
    Demobuf.Copy(FileData8);
    iFile.Close();
    }
    iFs.Close();
    By using this code I am able to read file
    Now I want to show my data into list box..
    but only some part of every line
    which is separated by '#'
    aaa#bbb#ccc#ddd#
    aa#bb#cc#ddddd#...

    like only aaa and ccc
    how can i do this???

  15. #15
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: getting substring from text file

    Basically its your own data, so you just need to make logic that ignores the parts that you don't use.

Similar Threads

  1. [moved] How can I supply a language text file in the resources folder
    By deksa13jakim in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2009-08-31, 09:39
  2. [moved] Carbide C++ - custom text file encoding
    By elviin in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2009-04-27, 17:58
  3. [moved] problem with text file reading
    By masoud_bayat in forum Symbian
    Replies: 5
    Last Post: 2008-10-05, 08:22
  4. [Moved] Appending contents to the Text File
    By jammulak in forum Mobile Java General
    Replies: 0
    Last Post: 2008-08-20, 07:07
  5. substring bug ?
    By nijel in forum Mobile Java General
    Replies: 9
    Last Post: 2006-08-21, 21:09

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×