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

StealthRT
  • 10,108
  • 40
  • 183
  • 342
  • Have you looked into using Regex? – Jeff Halverson Apr 18 '12 at 05:49
  • RegEX is beyound my comprehension... – StealthRT Apr 18 '12 at 06: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? – Jeff Halverson Apr 18 '12 at 06:08

1 Answers1

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/

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321