[2005] Parsing a textfile by Delimiters of Capital Words.
Hey Guys,
I was hoping someone could help me solve a problem I'm having using vb2005 to parse a text file. I'm trying to parse the text file by Sentences that start with Words that are all Captial. Such as, IVORY is a type of Plant.
The idea is parse a sentence at a time that starts with a Word in Full CAPs and place it in a collection.
Such as
"IVORY IS A PLANT" would be item 1 in collection
"SOMEBODY help me" would be item 2 in the collection.
the way the text file is its one solid block of sentences, with random carriage returns.
So I need the program to parse based off setences that start with word in full caps and ends before The next word with full caps. Since the document does not contain periods just commas that are using to complient the sentence not end it.
I've managed to write code that would place delimited values into collections using comma as the limiter. So that I could get the rest of the logic complete. I've tried using the built in commands to do this, however they seemt o only take fixed characters rather then muitiple ones.
Is there a way to check each word, and they when its found place the sentence in.
example:
myreader.textfieldtype= fileio.fieldtype.delimited
myreader.setdelimiters( string like [A-Z])
Any help you guys could offer would be great. Thx
The Code I'm using is.
using myreader as new microsoft.visualbasic.fileio.textfieldparser(".\star.txt")
myreader.textfieldtype = fileio.feildtype.delimited
myreader.setdelimiters(" ")
dim currentrow as string()
while not myreader.endofdata
try
current row=myreader.readfields()
dim currentfield as string
for each current field in currentrow
a=a+1
b.add(currentfield, a.tostring)
next
end try
end using
An example of the text file is.
DOBERMAN A BIG handsome
boy! 1 year, trained & clean, loves
kids! Reg’d, intact
ENGLISH Bulldog pups for sale
home-raised or visit:
www.affordablebullieswer.com
ENGLISH Bulldog pups, vet 4,
shots, dewormed, parents on site,
ready to go $1700
Re: [2005] Parsing a textfile by Delimiters of Capital Words.
I'm not sure I understood all that so this is probably not right. I simply went by the rule that: IF the first word of the current sentence is totally in capital letters, then that entire sentence would be wanted for the final collection. So from the list you posted at the end, this would be in a collection you could output:
DOBERMAN A BIG handsome
ENGLISH Bulldog pups for sale
ENGLISH Bulldog pups, vet 4,
Place a listbox on the form and place this code in a button click event or something.
2 Code:
Dim finalWords As New List(Of String)
Using SR As New IO.StreamReader("star.txt")
Dim tempStr As String = Nothing
Dim temp() As String
Dim isUpp As Boolean
Do While SR.Peek <> -1
tempStr = SR.ReadLine.Trim
temp = Nothing
temp = tempStr.Split(" "c)
isUpp = True
For Each ch As Char In temp(0).Trim
If Not Char.IsUpper(ch) Then
isUpp = False
End If
Next
If isUpp = True Then
finalWords.Add(tempStr)
End If
Loop
End Using
Me.ListBox1.Items.AddRange(finalWords.ToArray)
Re: [2005] Parsing a textfile by Delimiters of Capital Words.
Sorry for the late reply.
The problem I'm having has to do with a text file that format for each sentence only has one thing in common, they all begin with words that are in solid capitals.
An example of this file would be:
THE world is round and round THERE is nothing like being home SOMETIME I want to sleep.
THIS is a good day
to stay in bed and
sleep all day long.
NO body loves me.
This is an example of the text file. This also includes the spaces. between lines. I tried to write a program that counted the amount of capital letters in the word and if it was more then 2 it would place that in a string, and by using a flag and string builder put together a string, that would stop as soon as detected 2+ capital was detected. However I was not able to get this to work, the program would just do line by line, and would place in the container blank lines as well. Hopefully you guys have some insight as to how I can do this. Thank you.
Re: [2005] Parsing a textfile by Delimiters of Capital Words.
It will be easier to help if you post your code.