• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

VB.Net, Parsing 1 line of text with 6 numbers

I have a large (~200mb) text file that I have parsed through to the to this line:

Aged  Totals  :   50,076,431.27   31,279,697.69   12,354,684.77    2,512,658.58      735,177.66    3,194,212.57

I have this line set to a string variable called "Line".  The line will be different every day, but will always have 6 numbers.  My application has 6 variables (Value1, Value2, Value3, etc).  I am trying to set each of these values to one of these variables so that Value1 gets the left most number (50,076,431.27) and value 6 gets the right most number (3,194,212.57).  Any ideas on how to do this would be very helpful.  

Thanks.  
0
collages
Asked:
collages
3 Solutions
 
Bob LearnedCommented:
You could use the String.Split method, and look for values that aren't blank:

Dim list As New List(Of Decimal)
For Each number As String In inputString.Split(" ")
   If number.Length > 0 Then
      list.Add(Val(number.Replace(",", "")))
   End If
Next number

Bob
0
 
Fernando SotoCommented:
Hi  collages;

Or you can try this

        Dim Line As String = "Aged  Totals  :   50,076,431.27   31,279,697.69   12,354,684.77    2,512,658.58      735,177.66    3,194,212.57"
        Dim strValues() As String = Line.Substring(Line.IndexOf(":"c) + 1).Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
        Dim values As New List(Of Decimal)

        For idx As Integer = 0 To strValues.Length - 1
            values.Add(CDec(strValues(idx)))
        Next

Fernando
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Just for the heck of it...

    Public value1, value2, value3, value4, value5, value6 As Decimal

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Line As String = "Aged  Totals  :   50,076,431.27   31,279,697.69   12,354,684.77    2,512,658.58      735,177.66    3,194,212.57"
        Line = Line.Substring(Line.IndexOf(":") + 1)
        While Line.IndexOf("  ") >= 0
            Line = Line.Replace("  ", " ")
        End While
        Line = Line.Trim
        Dim values() As String = Line.Split(" ")
        If values.Length = 6 Then
            For i As Integer = 1 To 6
                Try
                    CallByName(Me, "Value" & i, CallType.Let, CDec(values(i - 1)))
                Catch ex As Exception
                End Try
            Next
        End If
        Debug.WriteLine(value1)
        Debug.WriteLine(value2)
        Debug.WriteLine(value3)
        Debug.WriteLine(value4)
        Debug.WriteLine(value5)
        Debug.WriteLine(value6)
    End Sub
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now