Rocky3598
Rocky3598

Reputation: 121

Find string VB.NET

I have a text file with multiple different items that I need to grab from it.

Here is portion of the text file:

JOB_NUMBER                      XXXX-XX              TYPE: String               
                                                     SOURCE: User-Defined       
                                                     ACCESS: Full               
                                                     DESIGNATED: NO             
                                                     DESCRIPTION:               

CUSTOMER                        SAMPLE COMPANY       TYPE: String               
                                                     SOURCE: User-Defined       
                                                     ACCESS: Full               
                                                     DESIGNATED: NO             
                                                     DESCRIPTION:               

OVERBURN                        5.500000e-03         TYPE: Real Number          
                                                     SOURCE: User-Defined       
                                                     ACCESS: Full               
                                                     DESIGNATED: NO             
                                                     DESCRIPTION: 

I need to find the string with JOB_NUMBER in it and grab the number "XXXX-XX" same with "CUSTOMER" but that will be a string not an integer.

This cannot be done by line number because it will be different every time.

Any suggestions would be very helpful

Upvotes: 1

Views: 398

Answers (3)

NeverHopeless
NeverHopeless

Reputation: 11233

You should also look at here.

Another example

Upvotes: 1

Steve
Steve

Reputation: 20469

Is there only going to be 1 job number and one customer string in each file? If yes you could read the file to a string and extract like so:

Dim thefile As String = IO.File.ReadAllText("C:\test.txt")
Dim jobnumber As String = Split(Split(thefile, "JOB_NUMBER")(1), "TYPE:")(0).Trim()
Dim customer As String = Split(Split(thefile, "CUSTOMER")(1), "TYPE:")(0).Trim()

Upvotes: 1

Bradley Thomas
Bradley Thomas

Reputation: 4107

If those are fixed width columns, simply find the lines that begin with JOB_NUMBER and CUSTOMER and substring out the middle column, then trim the spaces.

Upvotes: 0

Related Questions