Variable length text

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
G10L41T20P0C15D1.2S1I0E1.2H4.7262K0.J0Q1450N00000001
G10L41T21P0C19D0.87S1I0E0.875H5.9386K0.J0Q884N00000001
G10L41T22P0C2D0.53S1I0H7.3233K0.159B0J0Q236N00000001A0.
G10L41T23P0C15D0.25S1I0E0.25H7.2087K0.J0Q0N00000001
G10L41T24P0C15D0.75S1I0E0.75H7.4646K0.J0Q5253N00000001

Above is an example of the text I need to use. It comes from a CNC mill and is a text file of tool data. Actual useful data is separated by the alpha characters. After each alpha character is the value needed.

I would like to be able to step through each line and assign a value to a variable based on the numeric value after a specific alpha character.

Example:
T = ToolNumber = 20
C = ToolType = 15
D = ActualDia = 1.2
E = NominalDia = 1.2
H = ToolLength = 4.7262

Any ideas? The length of the numeric values vary.
 

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
I was thinking the same thing. I was able to get pretty close with these 2 patterns.

VB.NET:
Dim strNumbers() As String = System.Text.RegularExpressions.Regex.Split(str1,"[a-zA-Z]")
Dim strLetters() As String = System.Text.RegularExpressions.Regex.Split(str1,"\d\S")
 

MattP

Well-known member
Joined
Feb 29, 2008
Messages
1,206
Location
WY, USA
Programming Experience
5-10
I won't claim to be a Regex adept but this seemed to get the right results for me.

VB.NET:
		Dim input As String = "G10L41T20P0C15D1.2S1I0E1.2H4.7262K0.J0Q1450N000000 01"

		Dim output As New List(Of String)

		For Each m As Match In Regex.Matches(input, "[A-Z]\d*\.?\d+")
			output.Add(m.Value)
		Next
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Thank you

Awesome!
Thanks MattP, I was not dealing with the decimal point correctly.
Your expression gets the job done.
Thank you to all who replied.
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Ok, one more wrinkle in the equation.
There can be a instance where the "S" can be followed by a "-".
The dash will not always be there, but when it is, it means something.
So on some records I would want "S4" and on others I would want the "S-4".
Can that be done?

Thanks in advance.
 
Top Bottom