Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to filter a list like this sample 3

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
0
16
DE
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...
 
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 [Smile]ing

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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top