×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to filter a list like this sample
3

How to filter a list like this sample

How to filter a list like this sample

(OP)
I have a file in which the field (table of contents) contains the company name and a page number.
I would like to have these two terms separated into 2 extra columns
in the same file.
For me this is not a problem with the page numbers.
because they are always on the far right.
How do I isolate the company, the length of which is variable.

Example:
Company ...... ... Page
------------------------------------------------------
Walt Disney ...........3
IBM ..... .... ... ..... 21
3M Company.....105

etc

Thanks
Klaus



Peace worldwide - it starts here...
Replies continue below

Recommended for you

RE: How to filter a list like this sample

2
I think you are asking that one field (ToC) be split into two fields for later processing
The common characteristic is that the last 'word' on each entry is always the page number
the balance to the left of that being the company name, which might be 1 to n words long.

To get the page number you simply need to know how many words are in ToC and then take the last one.
VFP has a nice group of functions for this:

GetWordCount(cString[, cDelimiters])
and
GETWORDNUM(cString, nIndex[, cDelimiters])

So the page can be extracted thus:

CODE

m.PageNo = GetWordNum(myTable.ToC,GetWordCount(myTable.ToC)) 

The company name would be everything else, so if you find the last instance of the page number
in the ToC field, and then the company name is everything to the left of that.

CODE

m.CompanyName = Left(myTable.ToC,Rat(m.PageNo,myTable.ToC)-1) 

If you want these in new fields, you could do it in two passes (for clarity, not speed) like this

CODE

alter table myTable add column PageNo c(12) not null
alter table myTable add column CompanyName c(200) not null

Replace all PageNo      with  GetWordNum(myTable.Toc,GetWordCount(myTable.ToC))
Replace all CompanyName with  Left(myTable.ToC,Rat(myTable.PageNo,myTable.ToC)-1) 

You could easily combine the replace statements, and the ones adding the fields, into single expressions - but I think the intent is clearer this way.

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: How to filter a list like this sample

First use ALINES to have separate lines. Then use STREXTRACT() only specifying the end delimiter '.' for the company name and "last word" for the page number.

CODE

Clear

* could also be lcText = FileToStr('textfilename')
* or lcText = Memofieldname
Text to lcText noshow 
Company ...... ... Page
------------------------------------------------------
Walt Disney ...........3
IBM ..... .... ... ..... 21
3M Company.....105
EndText 

For lnLine = 1 to ALines(laLines,lcText)
*!*	   ? 'line starts'
*!*	   For lnWord = 1 to GetWordCount(laLines[lnLine],'.')
*!*	      ? GetWordNum(laLines[lnLine],lnWord,'.')
*!*	   EndFor 
*!*	   ? 'line ends'
   lcCompany = StrExtract(laLines[lnLine],'','.')
   lcPage = GetWordNum(laLines[lnLine],GetWordCount(laLines[lnLine],'.'),'.')
   * validation (only output when you find both comany and page number in a line)
   If Val(lcPage)>0
      ? lcCompany
      ? Int(Val(lcPage))
      ?
   EndIf 
EndFor 

Chriss

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close