Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Searching and displaying specific information

Searching and displaying specific information

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++databasealgorithmstutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gregarion
    wrote on last edited by
    #1

    Hey guys, im quite new to c++. i am doing a project in which i would have to extract certain information of a database which i have saved in a text file. the database looks something like this : Database John32451^23.21 >tyyhg>tdsrte^>1.24 Mark55342^ 335.11 >tsthh What i am trying to do is search each row based on a specific id and then extract the information next to it. For example, if i were to select John in the menu, the output will be like this. OUTPUT John 23.21 1.24 I am not very sure how could i do this and the method to use. Could i get some guidance? To get the correct line will be easy as we just have to search for the name to get the line. But , how about the other two information? I was thinking of using the characters before it which is "32451^" and then reading the info. but how do i get it to stop at the information i want and not continue displaying the information after that which is ";gt;t"

    L M 2 Replies Last reply
    0
    • G gregarion

      Hey guys, im quite new to c++. i am doing a project in which i would have to extract certain information of a database which i have saved in a text file. the database looks something like this : Database John32451^23.21 >tyyhg>tdsrte^>1.24 Mark55342^ 335.11 >tsthh What i am trying to do is search each row based on a specific id and then extract the information next to it. For example, if i were to select John in the menu, the output will be like this. OUTPUT John 23.21 1.24 I am not very sure how could i do this and the method to use. Could i get some guidance? To get the correct line will be easy as we just have to search for the name to get the line. But , how about the other two information? I was thinking of using the characters before it which is "32451^" and then reading the info. but how do i get it to stop at the information i want and not continue displaying the information after that which is ";gt;t"

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #2

      I suggest you put the data in a real database table. That way you can search the information you want using SQL instead of writing all the code to find the values you want from a text string.

      G 1 Reply Last reply
      0
      • L loyal ginger

        I suggest you put the data in a real database table. That way you can search the information you want using SQL instead of writing all the code to find the values you want from a text string.

        G Offline
        G Offline
        gregarion
        wrote on last edited by
        #3

        i cant do that cos the information is coming from a html file. so i have to read it as a text file then use unique id attibutes to make sure i am on the right string , and which line to get the info from. For example : Nasdaq</a></td><td><span class="streaming-datum" id="yfs_l10_^ixic">2,287.99<<td colspan="4"><div style="height: 0px; the information which i have to retrieve will be "2,287.99". i studied the code and i realize that , the id before it is unique,(id="yfs_l10_^ixic">) , so i can search for it. the problem i am having is how to i tell the prog to save the information which i want and not save the other lines of text?

        B 1 Reply Last reply
        0
        • G gregarion

          i cant do that cos the information is coming from a html file. so i have to read it as a text file then use unique id attibutes to make sure i am on the right string , and which line to get the info from. For example : Nasdaq</a></td><td><span class="streaming-datum" id="yfs_l10_^ixic">2,287.99<<td colspan="4"><div style="height: 0px; the information which i have to retrieve will be "2,287.99". i studied the code and i realize that , the id before it is unique,(id="yfs_l10_^ixic">) , so i can search for it. the problem i am having is how to i tell the prog to save the information which i want and not save the other lines of text?

          B Offline
          B Offline
          Bram van Kampen
          wrote on last edited by
          #4

          You need to write a Scanner. The simpelest way would be (but this may not suffice): You open the html file, and read it line by line. You then search for the string id="yfs_110...>" Your number follows this string, and the number ends before the deinmiter'<'. So, scan your string until you find the '<' and set it to 0. Voila, your required Number string, Copy it, and do with it as you please. Regards, :)

          Bram van Kampen

          G 1 Reply Last reply
          0
          • G gregarion

            Hey guys, im quite new to c++. i am doing a project in which i would have to extract certain information of a database which i have saved in a text file. the database looks something like this : Database John32451^23.21 >tyyhg>tdsrte^>1.24 Mark55342^ 335.11 >tsthh What i am trying to do is search each row based on a specific id and then extract the information next to it. For example, if i were to select John in the menu, the output will be like this. OUTPUT John 23.21 1.24 I am not very sure how could i do this and the method to use. Could i get some guidance? To get the correct line will be easy as we just have to search for the name to get the line. But , how about the other two information? I was thinking of using the characters before it which is "32451^" and then reading the info. but how do i get it to stop at the information i want and not continue displaying the information after that which is ";gt;t"

            M Offline
            M Offline
            Moak
            wrote on last edited by
            #5

            gregarion wrote:

            What i am trying to do is search each row based on a specific id and then extract the information next to it

            Have a look at regular expressions (RE). There are various libraries for C++, see Boost or CodeProject articles. Alternatively, you could pre-process the data with a Python or Perl script, they are ideal for this kind of work and have regular expressions built-in. You could scan line by line trough your HTML-input and with a regular expression test/extract the wanted information. Hope this helps, M

            Webchat in Europe :java: (only 4K)

            1 Reply Last reply
            0
            • B Bram van Kampen

              You need to write a Scanner. The simpelest way would be (but this may not suffice): You open the html file, and read it line by line. You then search for the string id="yfs_110...>" Your number follows this string, and the number ends before the deinmiter'<'. So, scan your string until you find the '<' and set it to 0. Voila, your required Number string, Copy it, and do with it as you please. Regards, :)

              Bram van Kampen

              G Offline
              G Offline
              gregarion
              wrote on last edited by
              #6

              Hey thanks for the tip. Is there any example programs or tutorial which u know that can help me with the problem i am having?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups