Results 1 to 4 of 4

Thread: [2005] Parsing a textfile by Delimiters of Capital Words.

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    2

    [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

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    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:
    1. Dim finalWords As New List(Of String)
    2.  
    3.         Using SR As New IO.StreamReader("star.txt")
    4.             Dim tempStr As String = Nothing
    5.             Dim temp() As String
    6.             Dim isUpp As Boolean
    7.  
    8.             Do While SR.Peek <> -1
    9.                 tempStr = SR.ReadLine.Trim
    10.                 temp = Nothing
    11.                 temp = tempStr.Split(" "c)
    12.  
    13.                 isUpp = True
    14.  
    15.                 For Each ch As Char In temp(0).Trim
    16.                     If Not Char.IsUpper(ch) Then
    17.                         isUpp = False
    18.                     End If
    19.                 Next
    20.  
    21.                 If isUpp = True Then
    22.                     finalWords.Add(tempStr)
    23.                 End If
    24.             Loop
    25.         End Using
    26.  
    27. Me.ListBox1.Items.AddRange(finalWords.ToArray)
    Last edited by stimbo; May 22nd, 2007 at 02:27 PM. Reason: clarfying routine
    Stim

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

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    2

    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.

  4. #4
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: [2005] Parsing a textfile by Delimiters of Capital Words.

    It will be easier to help if you post your code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width