To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old May 22nd, 2007, 12:58 PM   #1
guadian
New Member
 
Join Date: May 07
Posts: 2
guadian is an unknown quantity at this point (<10)
[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
guadian is offline   Reply With Quote
Old May 22nd, 2007, 01:58 PM   #2
stimbo
Frenzied Member
 
stimbo's Avatar
 
Join Date: Jun 06
Location: UK
Posts: 1,745
stimbo is a jewel in the rough (200+)stimbo is a jewel in the rough (200+)stimbo is a jewel in the rough (200+)
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)
__________________
Stim

Free VB.NET Book Chapter
Visual Basic 2005 Cookbook Sample Chapter

Last edited by stimbo; May 22nd, 2007 at 02:27 PM. Reason: clarfying routine
stimbo is offline   Reply With Quote
Old Jun 5th, 2007, 12:06 PM   #3
guadian
New Member
 
Join Date: May 07
Posts: 2
guadian is an unknown quantity at this point (<10)
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.
guadian is offline   Reply With Quote
Old Jun 5th, 2007, 12:31 PM   #4
campster
Hyperactive Member
 
Join Date: Jul 05
Posts: 392
campster is on a distinguished road (20+)
Re: [2005] Parsing a textfile by Delimiters of Capital Words.

It will be easier to help if you post your code.
campster is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Forum Jump


All times are GMT -5. The time now is 05:36 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.