0

I'm trying to look through the source I do not need a integer but it is trying to convert to integer..

I may be over thinking this but here is my code

Dim sourceString As String = New System.Net.WebClient().DownloadString("website.html")
Dim value() As String = Split(sourceString, "<option value=", " >")

'Conversion from string " >" to type 'Integer' is not valid.'

not looking for some one to re-write my code but looking for what I am doing wrong and explain if possible.

Thank you

user3698349
  • 89
  • 1
  • 1
  • 6
  • What is that third argument to split ( ` " >" ` ) supposed to do? Is that a typo? – John Coleman Dec 03 '17 at 23:42
  • Trying to get the numbers that's it – user3698349 Dec 03 '17 at 23:43
  • 2
    Use HtmlAgilityPack instead of trying to parse HTML yourself. – Dai Dec 03 '17 at 23:45
  • You passed three arguments to `Split()`, even if that wasn't your intention. The third (and optional) argument to split is an integer which limits how many items are split off. Since " >" isn't an integer, you get that error. @Dai is almost certainly right in the sense that parsing HTML on your own is both hard and error prone. Some wheels are best not reinvented. – John Coleman Dec 03 '17 at 23:51
  • @JohnColeman it's Microsoft.VisualBasic.Strings.Split (which does take 3 arguments) https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.split%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 (though the third is supposed to be an int, hence the error). it is not the core .net System.String.Split (at most 2 args) – Caius Jard Dec 03 '17 at 23:57
  • +1 to not trying to reinvent an HTML parser. See https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Caius Jard Dec 04 '17 at 00:03

1 Answers1

1

Try the "proper" .net way:

  Dim value() as String = sourceString.Split({"<option value=", " >"}, StringSplitOptions.None)

You may want to consider removing Imports Microsoft.VisualBasic From the top of the file. You might get a lot of compiler errors but they can be fixed. The VB helper namespace is most useful for vb6 programmers migrating and wanting something familiar; using it will generally only perpetuate the use of bad programming practices picked up during vb6 years - there isn't really a need to use it regularly if you're keen to encourage yourself to write .net as it was intended

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • same error, not to sure how I can tell a split to only use 2 arguments instead of all 3 value of type 'string()' cannot be converted to 'char' – user3698349 Dec 03 '17 at 23:58
  • It's not quite the same error, as it's not the same method, though there was a missing argument to my recommendation which meant the wrong overload of string.split was being called; sorry about that - try now (amended code) – Caius Jard Dec 04 '17 at 00:01
  • It's probably the best idea: parsing web pages is a fragile affair. If the service you're using has some form of api or web service provision, use that instead – Caius Jard Dec 04 '17 at 00:26