fork(1) download
  1. Imports System
  2. Imports System.Collections.Generic
  3.  
  4. Public Class Test
  5. Public Shared Sub Main()
  6. Dim Values As Double() = StringToDoubleArray("1,2.4,5.4,6,2", New String() {","})
  7. For Each d As Double In Values
  8. Console.WriteLine(d.ToString())
  9. Next
  10. End Sub
  11.  
  12. Public Shared Function StringToDoubleArray(ByVal Input As String, ByVal Separators As String()) As Double()
  13. Dim StringArray() As String = Input.Split(Separators, StringSplitOptions.RemoveEmptyEntries) 'Split the string into substrings.
  14. Dim DoubleList As New List(Of Double) 'Declare a list of double values.
  15.  
  16. For x As Integer = 0 To StringArray.Length - 1
  17. If Double.TryParse(StringArray(x), Nothing) = True Then 'Check that the string is parsable into a double.
  18. DoubleList.Add(Double.Parse(StringArray(x))) 'Add the double to the list.
  19. End If
  20. Next
  21.  
  22. Return DoubleList.ToArray() 'Convert the list into an array.
  23. End Function
  24. End Class
Success #stdin #stdout 0.05s 24240KB
stdin
Standard input is empty
stdout
1
2.4
5.4
6
2