parse text field

B

Bennie Sanders

Hello,

I have a text file with 142 lines, each line beginning with a job number
and a line number, like this:

"9426 1"
"9426 2"

through 9426142

I've used the left function to extract the 9426 but how can I separate
what's left over? The right function isn't returning the remaining
value properly because there aren't always three characters to the right
of 9426. I'm stumped. Any help would be appreciated. Thank you.
 
R

Ray at

TheRightPart = Right(yourValue, Len(yourValue) - Len("9426"))

Instead of Len("9426"), you could of course just put the number 4, but it's
a little clearer using a value or a constant as opposed to what could appear
as just an arbitrary number.

Ray at home
 
B

Blair Bonnett

I used to do it that way, but I've since found it better to use the Mid()
function. If you don't specify the 'end' variable, it will select
everything remaining in the string. So if you want to select everything
from the fifth character onwards, you would use:
TheRightPart = Mid(yourValue, 5)

IMHO, the Mid() function is best to select everything from a known
character position onwards, and the Right() function is best to select a
known number of characters.

Blair
 
R

Roland Hall

in message
: I have a text file with 142 lines, each line beginning with a job number
: and a line number, like this:
:
: "9426 1"
: "9426 2"
:
: through 9426142

What is after the job and line number on those lines and is there really 2
spaces between job and line number?

: I've used the left function to extract the 9426 but how can I separate
: what's left over? The right function isn't returning the remaining
: value properly because there aren't always three characters to the right
: of 9426.

There aren't always three characters or three numbers? You show two spaces
in the first two lines.

If there are always two spaces and more text on the line since you said
"each line beginning with a job number and a line number" then:

dim job, line, temp
str = "9426 1 some other text"
job = left(str,4)
line = trim(mid(str,5,3))

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Bennie Sanders

Ray,

Your method worked perfectly. Here's what I came up with:

PLANID=left(datcols(0),4)
LINE_NO = Right(datcols(0), Len(datcols(0)) - Len(PLANID))

LINE_NO is what I was trying to achieve and it works great. Many thanks
for your help and also to the others.

Bennie
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top