search for specific word in a text file
-
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
-
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
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.
-
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
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).
-
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).
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
returns0
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
-
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
returns0
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
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.
-
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.
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
-
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
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.
-
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.
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 theString
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