CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2002
    Posts
    936

    GetPrivateProfileString Reading Section With Multiple Keys

    I want to know if it is possible to use GetPrivateProfileString to read a section where the keys are duplicate. I try it, but I can only retreive one key. This is my file format

    [Section Name]
    KeyOne = ItemOne
    KeyOne = ItemTwo
    KeyOne = ItemThree

    For any reason, I can only retrieve item one. I want to know and how if I can format GetPrivateString in a form, where the first time it executes it will retrieve keyone from the first line, then go to the next line to read the next keyone.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    if it is possible to use GetPrivateProfileString to read a section where the keys are duplicate.
    No.

    Put 2 red sweaters in a box, and ask a bystander to get 'the red sweater' out of the box. The first question you get is 'which red sweater'. That's why you can only retrieve 1 item.

  3. #3
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    Why are you having the same names in the first place ?

  4. #4
    Join Date
    Jun 2002
    Posts
    936

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    In this case, I may need to use getline from std library to retrieve the items which are duplicate. So how can I use getline in this particular case?

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    A better question is why do you have duplicates and how can you remove them.

  6. #6
    Join Date
    Jun 2002
    Posts
    936

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    I try to use getline, but getline only stop reading before delimiter. I want to start reading after '=', not before. Is there a way I can modify it.

    PHP Code:

    streamFile
    .getline(myChar10'='); 

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    A better question is why do you have duplicates and how can you remove them

  8. #8
    Join Date
    Jun 2002
    Posts
    936

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    this is not an .ini file. It is an special purpose text file

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    Quote Originally Posted by vcstarter
    this is not an .ini file. It is an special purpose text file
    Sure looks like an INI. Regardless, why not come up with unique names?

  10. #10
    Join Date
    Jun 2002
    Posts
    936

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    I cannot modify the file. It is given as is

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    Then write your own parser!
    It is nor difficult: read each string, search for the '=', left part (before '=') would be the key and the rest (after the '=') - the value.
    Victor Nijegorodov

  12. #12
    Join Date
    Jun 2002
    Posts
    936

    Re: GetPrivateProfileString Reading Section With Multiple Keys

    OK I will do so, this is basically what I am working on now

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured