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

Published 22 June 07 04:59 PM

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

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# rstat1 said on June 25, 2007 11:23 AM:

Speaking of VS2008 Beta2, when is gonna be released?

# rstat1 said on June 25, 2007 11:23 AM:

Speaking of VS2008 Beta2, when is gonna be released?

# rstat1 said on June 25, 2007 11:23 AM:

Speaking of VS2008 Beta2, when is gonna be released?

# VBTeam said on June 25, 2007 12:14 PM:

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

# schildr said on June 28, 2007 9:51 AM:

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?

# Public Sector Developer Weblog said on July 3, 2007 8:24 AM:

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

# Noticias externas said on July 3, 2007 9:21 AM:

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

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker