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

6
  • What is that third argument to split ( ` " >" ` ) supposed to do? Is that a typo? Commented Dec 3, 2017 at 23:42
  • <option value="252059" > Trying to get the numbers that's it Commented Dec 3, 2017 at 23:43
  • 2
    Use HtmlAgilityPack instead of trying to parse HTML yourself. Commented Dec 3, 2017 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. Commented Dec 3, 2017 at 23:51
  • @JohnColeman it's Microsoft.VisualBasic.Strings.Split (which does take 3 arguments) msdn.microsoft.com/en-us/library/… (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) Commented Dec 3, 2017 at 23:57

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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'
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)
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.