 |
 |

07-22-2012, 11:00 PM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
parsing through a string
|
I need to assign a value to a variable by getting it from a text file. The value I need starts in column 15 and has an undetermined length.. I just know the value is followed by a blank so I would have to read numbers until I hit a blank. I need to load the variable into a list that I'm going to later compare against another table that I created. Does anyone know how I can do this?
TIA
Joni 
|
|

07-23-2012, 05:44 AM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
|
Read in the entire line. Use String.IndexOf() to find the index of the first blank. Then use String.Substring() to get the part of the string before the blank. Then use your method of choice to convert that substring into numbers. If you have any questions about those methods, check the documentation, then post what you've tried if that doesn't answer the question.
|
|

07-23-2012, 07:07 AM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
|
Thanks but I'm not sure that's going to work. Reason being that there are blanks randomly throughout the record, both before and after the field I need to pull. Is there a function that will start in a set location (column 15) and read the characters 1 by 1 until a specific character is hit (in this case, a blank)?
|
|

07-23-2012, 07:20 AM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
|
Yes, if you look at the documentation for String.IndexOf() you'll find there's an overload that lets you tell it where to start looking.
|
|

07-23-2012, 08:23 AM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
Thanks so much... I'll give it a try 
|
|

07-23-2012, 09:13 AM
|
 |
Centurion
|
|
Join Date: Jun 2003
Location: New Jersey
Posts: 150
|
|
I got it to work, but tried it a different way... probably cheated a bit but it works
Rpt_TotalRecs = Mid(Rpt_REC, 15, 10)
Rpt_TotalRecs = Rpt_TotalRecs.Trim
Thanks for your help.. it's very appreciated!
Joni
|
|

07-24-2012, 08:00 AM
|
|
Newcomer
|
|
Join Date: Oct 2008
Location: United Kingdom
Posts: 2
|
|
fixed length!!
|
Of course, passing a length of 10 into Mid won't help you if you have a field of indetermined length as you indicated in your OP. For this, you'd have to use Instr() to find the first occurrence of a space after position 15 and subtract 15 from this position.
Rpt_TotalRecs = Mid(Rpt_REC, 15, instr( Rpt_REC, 15, " ") -15)
This should return the string from position 15 to the position before the next occurring space char.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|