How to search specific string into text file from VB.NET





```
<pre><code></code>
```
How you do this will depend on a number of factors: since you haven't tried to explain in any detail, I'll assume you know nothing, and just give you the basics.  

  

The easiest way to do this is to read the text file into a single string, and then use the .NET framework to find the match:  


```
Dim text As String = File.ReadAllText("D:\Temp\MyFile.txt")
Dim index As Integer = text.IndexOf("hello")
If index >= 0 Then
   ' String is in file, starting at character "index"
End If
```
  

There are other ways, but that is pretty much the simplest.
How about in c++?



[http://www.1cplusplusstreet.com/vb/scripts/ShowCode.asp?txtCodeId=6877&lngWId=3](/posts/bad_link/258354?url=http%3A%2F%2Fwww.1cplusplusstreet.com%2Fvb%2Fscripts%2FShowCode.asp%3FtxtCodeId%3D6877%26lngWId%3D3) JavaScript *itself* has nothing built in for handling query string parameters. 


Code running in a (modern) browser you can use the [`URL` object](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) (which is part of the APIs provided by browsers to JS):





```
var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
```









For older browsers (including Internet Explorer), you can use [this polyfill](https://github.com/ungap/url-search-params) or the code from the original version of this answer that predates `URL`:


You could access `location.search`, which would give you from the `?` character on to the end of the URL or the start of the fragment identifier (#foo), whichever comes first.


Then you can parse it with this:





```
function parse_query_string(query) {
  var vars = query.split("&");
  var query_string = {};
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    var key = decodeURIComponent(pair[0]);
    var value = decodeURIComponent(pair[1]);
    // If first entry with this name
    if (typeof query_string[key]  "undefined") {
      query_string[key] = decodeURIComponent(value);
      // If second entry with this name
    } else if (typeof query_string[key]  "string") {
      var arr = [query_string[key], decodeURIComponent(value)];
      query_string[key] = arr;
      // If third or later entry with this name
    } else {
      query_string[key].push(decodeURIComponent(value));
    }
  }
  return query_string;
}

var query_string = "a=1&b=3&c=m2-m3-m4-m5";
var parsed_qs = parse_query_string(query_string);
console.log(parsed_qs.c);
```




You can get the query string from the URL of the current page with:



```
var query = window.location.search.substring(1);
var qs = parse_query_string(query);

``` You can use the XPATH syntax:



```
var span = doc.DocumentNode.SelectSingleNode("//span[@class='dropDownButton ownCity coords']");
var anchorText = span.ChildNodes["a"].InnerText;

```

You can also use LINQ:



```
var anchorTexts = 
    from span in doc.DocumentNode.Descendants("span")
    where span.GetAttributeValue("class", "") == "dropDownButton ownCity coords" 
    from anchor in span.Descendants("a") 
    select anchor.InnerText;
string anchorText = anchorTexts.FirstOrDefault();

``` try a quick search on google with your key words. Try [Javascript .NET](https://github.com/JavascriptNet/Javascript.Net). It is hosted on GitHub It was originally hosted on CodePlex, [here](http://javascriptdotnet.codeplex.com))


Project discussions: <http://javascriptdotnet.codeplex.com/discussions>


It implements Google V8. You can compile and run JavaScript directly from .NET code with it, and supply CLI objects to be used by the JavaScript code as well. It generates native code from JavaScript. [image] nirgrahamuk:

observe({

fv <- req(input$filter\_var)

td <- req(tabledata())

updateselectizeinput(inputid = "filter\_vals",

choices = pull(td,fv))

})

observe({

fv <- as.character(req(input$filter\_var))

td <- req(table… hi andy,  

  

could you please explain in more details what exactly you need to achieve, because i am still not sure i understand you correctly?  

  

please note that when you are using the code below, you are overriding the text of the selected item - in your case this is the first item in the radcombombobox(with the empty text):  


`ddlfuturecode.selecteditem.text =` `"futurecode"`

  

if you want to select an item from the radcombobox by its text, you can use the following code instead:  


`ddlfuturecode.finditembytext(``"futurecode"``).selected =` `true`

  

so the changed vb code should look like the following:  


`dim` `ddlfuturecode` `as` `new` `radcombobox`
 
`with` `ddlfuturecode`
`.items.clear()`
`.items.add(``new` `radcomboboxitem(``""``, 0))`
`.items.add(``new` `radcomboboxitem(``"1"``, 1))`
`.items.add(``new` `radcomboboxitem(``"futurecode"``, 2))`
`.databind()`
`end` `with`
 
`ddlfuturecode.finditembytext(``"futurecode"``).selected =` `true`
 
`form1.controls.add(ddlfuturecode)`

  

  

regards,  

 aneliya petkova   

telerik

do you want to have your say when we set our development plans?
do you want to know when a feature you care about is added or when a bug fixed?
explore the [telerik feedback portal](http://www.telerik.com/support/feedback)
and vote to affect the priority of the items I'm not going to go through all of your code because I'm in a hurry, but this should simplify it quite a bit. At a minimum it will make it easier to read.



```
alphabet = ['A','B','C','D'....etc]
count = 0
infile = open('infile.txt','r')
for character in infile.readlines():
    if character in alphabet:
        count += 1

print count
``` hello,

there are more possibilities how write output to file. first is by standard methods of jscript by “scripting.filesystemobject”.

var fso = new activexobject(“scripting.filesystemobject”);

var forreading = 1;

var forwriting = 2;

if (fso.fileexists(‘c:\test.txt’))

var f1 = fso.opentextfile… [@cssc](/u/cssc), another option would be to take the regex way.

first, it finds the index of the 5th pipe.

then, it takes the substring until that index.

give this a try:

inputstr.substring(0, regex.matches(inputstr, "\|")(4).index + 1)