Regular Expressions........

H

Higgim Batham

Is there any efficient way to get the data from the following string using
the regular expressions?



Dim strTestData as String = "CST123CENTST7872828TENFST1234FEN"



In the case I am populating a variable with three values.



Customer Id : CST123CED

Where CST --->Customer ID STarting point

CED--àCustomer ID ENding point

I am keeping a value customer Id in between these two strings.



Similarly TST-> Telephone # Start point

TEN-> Telephone # ENding point



FST and FEN to store the FAX numbers.



The number of characters between start and end point will vary.



How to read the data from this string using regular expressions. I want to
read the customer Id, telephone #... etc



Higgim Batham
 
C

Chris R. Timmons

Is there any efficient way to get the data from the following
string using the regular expressions?

Dim strTestData as String = "CST123CENTST7872828TENFST1234FEN"

<code snipped>

How to read the data from this string using regular expressions.
I want to read the customer Id, telephone #... etc

Higgim,


' Untested code.

Imports System.Text.RegularExpressions

....

Dim m As Match = Regex.Match(input, "^CST(?<customerId>.*?)CENTST(?<telephoneNumber>.*?)TENFST(?<faxNumber>.*?)FEN$")

Dim customerId As String = m.Groups["customerId"].ToString()
Dim telephoneNumber As String = m.Groups["telephoneNumber"].ToString()
Dim faxNumber As String = m.Groups["faxNumber"].ToString()
 
H

Higgim Batham

I am getting the following error.
"Identifier expected"
I am using .NetFramework 1.1.
Thanks,
Higgim



Chris R. Timmons said:
Higgim,


' Untested code.

Imports System.Text.RegularExpressions

...

Dim m As Match = Regex.Match(input,
^CST(? said:
Dim customerId As String = m.Groups["customerId"].ToString()
Dim telephoneNumber As String = m.Groups["telephoneNumber"].ToString()
Dim faxNumber As String = m.Groups["faxNumber"].ToString()
 
H

Higgim Batham

I changed the code as follows.

Dim customerId As String = m.Groups("customerId").ToString()
Dim telephoneNumber As String = m.Groups("telephoneNumber").ToString()
Dim faxNumber As String = m.Groups("faxNumber").ToString()

It started working fine.
Thanks,
Higgim



Higgim Batham said:
I am getting the following error.
"Identifier expected"
I am using .NetFramework 1.1.
Thanks,
Higgim



Chris R. Timmons said:
Higgim,


' Untested code.

Imports System.Text.RegularExpressions

...

Dim m As Match = Regex.Match(input,
^CST(? said:
EN$")

Dim customerId As String = m.Groups["customerId"].ToString()
Dim telephoneNumber As String = m.Groups["telephoneNumber"].ToString()
Dim faxNumber As String = m.Groups["faxNumber"].ToString()
 
H

Higgim Batham

Chris,
This is what exactly I wanted and it works for me.
Thanks for the code.
Higgim

Chris R. Timmons said:
Higgim,


' Untested code.

Imports System.Text.RegularExpressions

...

Dim m As Match = Regex.Match(input,
^CST(? said:
Dim customerId As String = m.Groups["customerId"].ToString()
Dim telephoneNumber As String = m.Groups["telephoneNumber"].ToString()
Dim faxNumber As String = m.Groups["faxNumber"].ToString()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top