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

Posted on 2007-08-01
Last Modified: 2010-07-27
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.  

Question by:collages
    LVL 96

    Accepted Solution

    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

    LVL 62

    Assisted Solution

    by:Fernando Soto
    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

    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    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
                        CallByName(Me, "Value" & i, CallType.Let, CDec(values(i - 1)))
                    Catch ex As Exception
                    End Try
            End If
        End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now