×

Discussion Board

Results 1 to 8 of 8

Thread: search display

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    32

    search display

    i have a txt file like this :

    11111 aaaa
    22222 bbbb
    33333 ccccc
    .......


    i want to write a code that search for "bbbb" in the file and display on the screen "22222".

    i wrote this code wich read a file kaka.txt, and display all the content on the screen :

    _LIT(filename, "c:\\kaka4.txt");
    RFs iRFs;
    RFile iFile;
    TFileText fileText;

    TFileName aPath;
    aPath.Append(filename);
    iRFs.Connect();
    iFile.Open(iRFs, aPath, EFileStream);
    fileText.Set(iFile);
    TBuf<250> service;
    fileText.Read(service);

    iFile.Close();
    iRFs.Close();


    CAknInformationNote* informationNote;
    informationNote = new (ELeave) CAknInformationNote;
    informationNote->ExecuteLD(service);


    can some one help me to complete it?

    thanks

  2. #2
    Regular Contributor
    Join Date
    May 2004
    Location
    NRW/ Germany
    Posts
    188
    Take a look at the TLex. I think it could help you. Haven't found another way yet to get the number back out of the TBuf.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    32

    not clear

    do i have to convert Tbuf to char?

  4. #4
    Regular Contributor
    Join Date
    May 2004
    Location
    NRW/ Germany
    Posts
    188
    I solved it like this:

    TBuf<250> service;
    fileText.Read(service);
    TLex lex;
    lex.Assign(service);

    Then you can use MarkedToken() and NextToken() to get your bbbb and 22222 and then you have to convert the "22222" back in TInt with Val().

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    32

    help

    i dont know how i use MarkedToken(), and i didnt find an example in this forum,

  6. #6
    Regular Contributor
    Join Date
    May 2004
    Location
    NRW/ Germany
    Posts
    188
    Ok, I'll try to explain, but I don't know if it's right. It works:

    TBuf<250> service;
    fileText.Read(service); // service is like: "11111 aaaa 22222 bbbb 33333 ccccc"
    TLex lex;
    lex.Assign(service); // so lex looks like service

    Now you can do:
    lex.Mark(); //you mark the beginning of the string, just in case
    lex.SkipCharacters(); // you skip all characters till the end of the token. Tokens are divided by spaces.
    TPtrC firsttoken = lex.MarkedToken(); // so firsttoken is a pointer to the 11111

    Hope it helps

  7. #7
    Registered User
    Join Date
    May 2004
    Posts
    32
    do you know how can i display on the screen firsttoken[1] or firsttoken[2] ? (for testing the code)

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    32
    i can now resume my problem like that :

    i have a txt file :
    111 222 333

    i want to write a code that read the file , take the integer 222 and display it on the screen, so i wrote this code :

    after reading file :

    TLex lex;
    lex.Assign(service);
    lex.Mark(); //you mark the beginning of the string, just in case
    TInt extractReal;

    lex.Val(extractReal);

    TBuf16<256> tgt;
    _LIT16(KFormat2,"%i");
    tgt.Format(KFormat2,extractReal);



    CAknInformationNote* informationNote;
    informationNote = new (ELeave) CAknInformationNote;
    informationNote->ExecuteLD(tgt);


    this code display only 111 on the screen, i added functions like :
    //lex.SkipSpace();
    //lex.SkipSpace();
    //lex.SkipAndMark();
    //lex.SkipSpaceAndMark();
    //lex.SkipCharacters();

    before the line lex.Val(extractReal); but it dos not work.


    dos some one has an idea?

Posting Permissions

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