VB.NET - How to grab specific part of text from a local html file and use it as variable? -


i making small "home" application using vb. title says, want grab part of text local html file , use variable, or put in textbox.

i have tried this...

private sub open_button_click(sender object, e eventargs) handles open_button.click     dim openfiledialog new openfiledialog()     openfiledialog.checkfileexists = true     openfiledialog.checkpathexists = true     openfiledialog.filename = ""     openfiledialog.filter = "all|*.*"     openfiledialog.multiselect = false     openfiledialog.title = "open"      if openfiledialog.showdialog = windows.forms.dialogresult.ok         dim filereader string = my.computer.filesystem.readalltext(openfiledialog1.filename)             textbox.text = filereader     end if end sub 

the result load whole html code inside textbox. should grab specific part of html files's code? let's want grab word text span...<span id="something">this text!!!</a>

i make following assumptions on answer.

  1. your html valid - i.e. id unique in document.
  2. you have id on html tag
  3. you'll using same tag (e.g. span)

i'd this:

' html document   dim filereader string = my.computer.filesystem.readalltext(openfiledialog1.filename)  ' split html text based on span element  dim filesplit string() = filereader.split(new string () {"<span id=""something"">"}, stringsplitoptions.none)  ' last part of text  filereader = filesplit.last  ' need trim after close tag  filesplit = filereader.split(new string () {"</span>"}, stringsplitoptions.none)  ' first part of text   filereader = filesplit.first  ' filereader variable should contain contents of span tag id "something" 

note: code untested , i've typed on stack exchange mobile app, there might auto correct typos in it.

you might want add in error validation such making sure span element occurs once, etc.


Comments