Solved

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

Posted on 2007-08-01
204 Views
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
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
End If
Next number

Bob
0

LVL 62

Assisted Solution

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
Next

Fernando
0

LVL 85

Assisted Solution

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

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 …
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 (http://msdn.microsoft.com/en-us/library/system.string.aspx) 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…