Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read a string and export values.

Status
Not open for further replies.

bobbyforhire

Technical User
Mar 11, 2008
253
US
I am looking to find a way to read a string and export valuse as needed.

For example string will contain this.


BOBBY, 15.00, 26.50, 33.00

AND OR

BOBBY,BOBBY 150.00, 260.00, 33.00


The name might contain an extra comma and or might contain an extra space in it.

The name and amount will be diffrent every time.

In the end i'm looking to put this into a field on the vb form.

Name: BOBBY,BOBBY
Ammount: 150.00

I'm using VB/vs2008 and can't for the life of me figure this one out. i'm guessing some sort of string manipulation

So really, is there any way i can tell VB to read a string until it reaches a Number. And is there any way i can tell it to read the number after it until it reaches a comma.

Thanks in advance.
 
This might be overkill but you could do this with Regular Expressions (include an Imports System.Text.RegularExpressions), something like:
Code:
Dim strInput As String = "BOBBY,         15.00, 26.50, 33.00"
        Dim strPattern As String = "(^[^0-9]+?)(\s{2,})(\d{1,6}\.\d{1,6})"
        Dim RegExp As New Regex(strPattern)

        Dim oMatch As Match
        oMatch = RegExp.Match(strInput)
        TextBox1.Text = oMatch.Groups(1).ToString
        TextBox2.Text = oMatch.Groups(3).ToString
Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Well alread hit my first snag,

Dave, Davis 111, 255.00,255.00

Don't know why 111 is there but it is to say the least, any way to just now tell it if it's see's 3 spaces in a row thats a line break?

This one is getting weird.
 
You can change the pattern to:
Code:
"(^.+?)(\s{3,})(\d{1,6}\.\d{1,6})"
That will take anything before at least three spaces and then the first number value after when used with the rest of the code provided.

Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top