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
  1. Home
  2. General Programming
  3. Visual Basic
  4. search for specific word in a text file

search for specific word in a text file

Scheduled Pinned Locked Moved Visual Basic
helptutorial
8 Posts 4 Posters 26 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.
  • B Offline
    B Offline
    Benjamindh
    wrote on last edited by
    #1

    hello everyone how are you, as always asking for your great help that you have given me, it happens that I have a text document, where I can look for information in a text file, if it finds it, assign that value found in a variable to me format of the text that I have is this, the text document contains several names Example Text file aof.zip:Art Of Fighting / Ryuuko no Ken Search: aof.zip once finder save in a variable the name that is after the : Show: Art Of Fighting / Ryuuko no Ken

    L R 2 Replies Last reply
    0
    • B Benjamindh

      hello everyone how are you, as always asking for your great help that you have given me, it happens that I have a text document, where I can look for information in a text file, if it finds it, assign that value found in a variable to me format of the text that I have is this, the text document contains several names Example Text file aof.zip:Art Of Fighting / Ryuuko no Ken Search: aof.zip once finder save in a variable the name that is after the : Show: Art Of Fighting / Ryuuko no Ken

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use a TextReader Class (System.IO) | Microsoft Docs[^] to read the file. Test if the line starts with the search field and if so use String.Split Method (System) | Microsoft Docs[^] to get the text following the colon.

      1 Reply Last reply
      0
      • B Benjamindh

        hello everyone how are you, as always asking for your great help that you have given me, it happens that I have a text document, where I can look for information in a text file, if it finds it, assign that value found in a variable to me format of the text that I have is this, the text document contains several names Example Text file aof.zip:Art Of Fighting / Ryuuko no Ken Search: aof.zip once finder save in a variable the name that is after the : Show: Art Of Fighting / Ryuuko no Ken

        R Offline
        R Offline
        Raphael Adeniji
        wrote on last edited by
        #3

        Hey guy, if you are using VB, it has a function called Instr. This function compares the two strings and returns integer value. If the value returned is greater than 0, that means that is the starting position of the word you are searching for, otherwise it will return -1 if not found. Note:- Ensure you convert the two strings to the same case before comparing(Upper or Lower case characters).

        Richard DeemingR 1 Reply Last reply
        0
        • R Raphael Adeniji

          Hey guy, if you are using VB, it has a function called Instr. This function compares the two strings and returns integer value. If the value returned is greater than 0, that means that is the starting position of the word you are searching for, otherwise it will return -1 if not found. Note:- Ensure you convert the two strings to the same case before comparing(Upper or Lower case characters).

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Either you're using VB6, which has been dead for over 20 years now... ... or you're still using the VB6-compatibility methods in VB.NET code, which is a recipe for poor performance and ugly code. :doh: Also, InStr returns 0 when a match is not found, not -1.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          R 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Either you're using VB6, which has been dead for over 20 years now... ... or you're still using the VB6-compatibility methods in VB.NET code, which is a recipe for poor performance and ugly code. :doh: Also, InStr returns 0 when a match is not found, not -1.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            R Offline
            R Offline
            Raphael Adeniji
            wrote on last edited by
            #5

            Of course I stopped using VB like 5 or 6 years ago, but the person that needs help posted it under VB. I use C# and the approach is different in C#. You answer questions in the context of where it is posted. I will not use C# to answer VB questions, everyone has his own reasons for choosing a language. For the returned value in search string, I used VB last in 2016 or 2017 and I indicated I was not sure what it would return, but either 0 or -1 to indicate it was not contained in the search string. As we speak, some companies have huge applications they developed in VB6 and they are a major source of income to their companies, are they going to throw them away because we now have Dot Net Core? That will be crazy! So we help to provide solutions in their context.

            Richard DeemingR 1 Reply Last reply
            0
            • R Raphael Adeniji

              Of course I stopped using VB like 5 or 6 years ago, but the person that needs help posted it under VB. I use C# and the approach is different in C#. You answer questions in the context of where it is posted. I will not use C# to answer VB questions, everyone has his own reasons for choosing a language. For the returned value in search string, I used VB last in 2016 or 2017 and I indicated I was not sure what it would return, but either 0 or -1 to indicate it was not contained in the search string. As we speak, some companies have huge applications they developed in VB6 and they are a major source of income to their companies, are they going to throw them away because we now have Dot Net Core? That will be crazy! So we help to provide solutions in their context.

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              There's nothing in the question to indicate that they're using VB6 rather than VB.NET; unless otherwise specified, it's safest to assume the OP is not using a dead language. :)


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              R 1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                There's nothing in the question to indicate that they're using VB6 rather than VB.NET; unless otherwise specified, it's safest to assume the OP is not using a dead language. :)


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                R Offline
                R Offline
                Raphael Adeniji
                wrote on last edited by
                #7

                Instr function is not specific to VB6, it is also in VB.Net, perhaps you don't know and secondly you should check the forum title. The forum title where we are discussing is Visual Basic, so the reason I suggested VB function to them.

                Richard DeemingR 1 Reply Last reply
                0
                • R Raphael Adeniji

                  Instr function is not specific to VB6, it is also in VB.Net, perhaps you don't know and secondly you should check the forum title. The forum title where we are discussing is Visual Basic, so the reason I suggested VB function to them.

                  Richard DeemingR Offline
                  Richard DeemingR Offline
                  Richard Deeming
                  wrote on last edited by
                  #8

                  As I said previously, InStr in VB.NET is a VB6-compatability method. Any VB.NET code written in the last twenty years (as opposed to code migrated from VB6) should be using the far superior methods available on the String class[^]. And just because there aren't separate "VB.NET" and "VB6" forums doesn't mean we should assume all questions posted here refer to a language which has been dead for two decades.


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  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