0

I need to take this string:

Dim tmpTry As String = "10, 20, 30, 40, 50, 52, 20, 20, 10, 35, 3, 8, 47, 7, 2, 5, 55, 8, 0, 0, 6, 55, 0, 2, 12, 0, 0, 21, 14, 0, 3"

And convert it to a double array:

Dim arrNumOfVisits As Double() = New Double(tmpTry) {}

How do i go about doing that?

FYI the arrNumOfVisits goes into a ParamArray System.Collections.IEnumerable()

David

3
  • Have you looked into using Regex? Commented Apr 18, 2012 at 5:49
  • RegEX is beyound my comprehension... Commented Apr 18, 2012 at 6:02
  • 1
    I'm not going to be able to offer a total solutions because I'm not that great at Regex, or vb.net (I use c#), but this may get you looking the right direction: "string[] numbers = Regex.Split(input, @"\D+");" gets you an array of strings that are numbers separated by non-numbers. Perhaps a simple cast to double will work? Commented Apr 18, 2012 at 6:08

1 Answer 1

2
Dim arrString As String() = tmpTry.Split(New Char() {" "C})
Dim arrNumOfVisits As Double() = New Double(arrString.Length) {}
Dim i As Integer = 0
While i < arrString.Length
    arrNumOfVisits(i) = Double.Parse(arrString(i))
    i += 1
End While

The above code will do the trick, using regEx on this would be overkill.

Never the less do try to learn the basic RegEx operations, here are my favorite cheat sheets: http://regexlib.com/CheatSheet.aspx?AspxAutoDetectCookieSupport=1
http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/

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

Comments

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.