LINQ Cookbook, Recipe 2: Find all capitalized words in a phrase and sort by length (then alphabetically) (Kit George)

LINQ Cookbook, Recipe 2: Find all capitalized words in a phrase and sort by length (then alphabetically) (Kit George)

  • Comments 7

Ingredients:

-          Visual Studio 2008 (Beta2 or Higher)

-     Some text you want to search

 

Categories: LINQ-To-Objects, LINQ and strings, LINQ and WinForms

 

Instructions:

-          Open Visual Studio 2008, and Click ‘File/New Project’. Find and double-click the ‘Windows Forms Application’ Icon

-          Drag and drop a Listbox to the form. Size the listbox to be fairly tall. Drag and drop a button to the form

-          Double-click the button, and add the following code to the button:

 

        Dim text = "Good morning everyone. I'd like to welcome " & _

                   "you to today's presentation on LINQ. My " & _

                   "name is Kit George and I'm a Program Manager " & _

                   "for Microsoft, on the Visual Basic team. You " & _

                   "might be wondering where my accent is from? " & _

                   "Well, I hail from a small country called New " & _

                   "Zealand but it sure is great to be here in  " & _

                   "Atlanta today!"

 

        Dim capitalWords = _

                      From word In text.Split( _

                      New Char() {",", ".", "!", " "}, _

                      StringSplitOptions.RemoveEmptyEntries) _

                      Where word(0) = Char.ToUpper(word(0)) _

                      Order By word.Length, word

 

        ListBox1.Items.AddRange(capitalWords.ToArray())

 

-          Change the text being searched to the text of your choice. If your text is coming from a file, use My.Computer.FileSystem.ReadAllText to get the data into the text variable

Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post
  • Speaking of VS2008 Beta2, when is gonna be released?

  • Speaking of VS2008 Beta2, when is gonna be released?

  • Speaking of VS2008 Beta2, when is gonna be released?

  • We're working on it hard right now, expect it to be available in the next couple of months!

  • Many times I need to create a comma delimited list of the checked items in a CheckedListBox. Is this something that LINQ can help with?

  • The VB team just started a LINQ Cookbook series. These are great because they show you how you can easily

  • The VB team just started a LINQ Cookbook series. These are great because they show you how you can easily

Page 1 of 1 (7 items)