Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > parse text field

Reply
Thread Tools

parse text field

 
 
Bennie Sanders
Guest
Posts: n/a
 
      04-22-2004


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.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      04-22-2004
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


"Bennie Sanders" <> wrote in message
news:%...
>
>
> 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.
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
 
Blair Bonnett
Guest
Posts: n/a
 
      04-22-2004
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

Ray at <%=sLocation%> [MVP] <myfirstname at lane34 dot com> wrote in
article <O5oq#>...
> 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

 
Reply With Quote
 
Roland Hall
Guest
Posts: n/a
 
      04-22-2004
"Bennie Sanders" wrote in message
news:%...
: 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


 
Reply With Quote
 
Bennie Sanders
Guest
Posts: n/a
 
      04-22-2004


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Ray at
Guest
Posts: n/a
 
      04-22-2004
I agree. This is a bit more pleasant to look at!

Ray at work

"Blair Bonnett" <> wrote in message
news:01c4282e$859d4620$309460cb@default...
> 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
>
> Ray at <%=sLocation%> [MVP] <myfirstname at lane34 dot com> wrote in
> article <O5oq#>...
> > 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
Placing the selection of a list field in a text field Jerry Manner HTML 5 06-09-2005 01:52 PM
writing from hidden field to text field Roy Adams Javascript 1 12-20-2004 03:47 AM
Changing drop-down field to text field. ehm Javascript 2 09-24-2003 07:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57