Break up a sentence into words

A user enters a sentence and I need to break up each word. I know how to convert the sentence to CAPS. But I need to break it up and then compare the word with a word in an array. How would I do this. I've been working on this for weeks!

Thanks

I tried something like this
   If sentence.Substring(m, n) = phrase Then
            strand &= word(i).FrenchWord & " "
            m = n + 1
            End If

Phrase=user input word
grundyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NipNFriar_TuckCommented:
How about this...

string mySentence = "foo bar baz";
string[] myWords = mySentence.Split( ' ' );

now each word in the sentence is an element int he string array.

Then you can loop through the words like so..

for ( int i = 0; i < myWords.Length; i++ ) {
   if ( myWords[i].ToUpper().Equals( phrase.ToUpper ) ) {
      //DO something
   }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
suprapto45Commented:
Hi,

What programming language do you use? I can help you in Java and Visual Basic.

Dave
0
NipNFriar_TuckCommented:
Woops, sorry thought I was looking at the C# language... now that I look at this closer this looks more like C or C++ and mine is rusty at the moment...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

grundyAuthor Commented:
This is VB.net
0
NipNFriar_TuckCommented:
Ah... cool then my suggestion should work.
0
grundyAuthor Commented:
NipNFriar,

How would I compare to an array of words that are in alphabetical order. The words are stored in an array as follows:

  Dim sr As IO.StreamReader = IO.File.OpenText("English, French, German.txt")
        Do While (sr.Peek  -1)
            i += 1
            word(i).EnglishWord = sr.ReadLine
            word(i).FrenchWord = sr.ReadLine
            word(i).GermanWord = sr.ReadLine
        Loop
0
suprapto45Commented:
Hi,

8. Creating arrays with the Split(split-character) function.
This function allows you to create a one-dimensional array, by splitting a string by recognizing a certain character, then putting any text after the character on a new line in the array.
This code will pop up a message box For each item in the array, which is 4. Note that the first line is infact 0.

    Dim i As String = "Line 0|Line 1|Line 2|Line 3"
    Dim a() As String
    Dim j As Integer
    a = i.Split("|")
    For j = 0 To a.GetUpperBound(0)
    MsgBox(a(j))
    Next
   
Another use of this function could be for getting all the lines from a multiline text box as follows: This will pull all lines of the text box, and use them to create an array, which is stored in r. You extract these values from the array by selecting where in the array you wish to look. The look-in-line is defined after the r, in brackets. Example: Msgbox r(3) would pull the FORTH line of the array that is being held in r. Msgbox r(5) would pull the 6th line being held in the array.

    Dim a() As String
    Dim j As Integer
    a = TextBox1.Text.Split(Lf)
   
    For j = 0 To a.GetUpperBound(0)
    MsgBox(a(j))
    Next


I get that from
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=169&lngWId=10

I hope that helps.

Regards
Dave
0
NipNFriar_TuckCommented:
Hmmm.... If word is a collection or dictionary then you could use the contains method... is it possible to use that instead of an array?
0
vippxCommented:
Hi,

If you need advanced string processing, splittling various kinds of strings into sub strings and a uniform metod of accessing it, then use of a concept of tokenizer offers a lot of power and flexibility. This StringTokenizer is a class implemented in Java by default, however for C# and also for understanding the concept better, here is code that provides a tokenizer class with its source and explanation on using it

http://www.codeproject.com/csharp/StringTokenizer.asp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.