View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Extract paragraphs from text file (new task)

Hi again Gary! I wanted to approach this a new way.
Suppose I have the following test input, which has 3 paragraphs:

[BEGIN INPUT]
playboys regrows correality requisition droits offered
angeles surfy wile lacrimation aged seignories practicing
hereinto workmanship fuggy municipally asdf underpinnings
brocket unpremeditated pinochle crazier coaeval obviously
able supinated hostler burrows artichoke vivant crosstown
********************
baneful celebrations angle growler landscape beside tzetzes
normal bootery bespoke henhouses tribuneship bouncer
displeasure crewman tenth curarization honestness sensitize
reminisces cometh fuk obscurantists eventualities mechanics
vanity crap nonalignment dowering nephew nonconfidence
********************
chaotically sooners rocketing luckiest holeproof damnableness
soc infertilely supernumerary expertise sulphid frisson
surceases joyously kins drooled agrarianism paraphrases ribby
wittiness grabbiest junketer accumulable hemokonia matriculants
sieged yuio forgoes *staking* nonadjacent offprint mug pawpaw
[END INPUT]


I just want to read the entire file and store each paragraph into
it's own string variable or array. What is an efficient way to
achieve this? (Dont worry about profanity words)

By the way, each paragraph will always be separated by a
border of 25 star characters, except for the first and last
paragraph.

Sorry if I wasn't clear earlier. ~Rob


I must be missing something because in my tests of my sample code I got
3 separate paragraphs in my array, 0 thru 2. I'm not sure you realize
that no matter how you look at it, each whole paragraph is handled as a
whole paragraph. So...

vData(0) contains paragraph1
vData(1) contains paragraph2
vData(2) contains paragraph3

...as examined in this array resulting from splitting the file by the
asterisk lines...

'Group directly into paragraphs
vData = Split(ReadTextFile(sFilename), String(25, "*"))

Perhaps the file contents you're working with are not structured
*exactly* as posted! It shouldn't matter where empty lines occur
because they get removed before the file gets overwritten...

'Filter out any blank lines
For n = UBound(vData) To LBound(vData) Step -1
If Len(vData(n)) = 0 Then vData(n) = "~"
Next 'n
vData = Filter(vData, "~", False)

WriteTextFile Join(vData, vbCrLf), sFilename
End Sub

OR
Perhaps you don't understand arrays, and so do not realize what the
code is doing (despite the descriptive comments)!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion