Reviews US Money Reserve research paper Motivational Quotes  ServicesListed.com Free cell phones   Custom Writing
Try the best slots i found online, you will love it!
Nishanth's Blog | Method to sort an array of strings in descending order of number of words in each array element

Method to sort an array of strings in descending order of number of words in each array element

by Nishanth 2. November 2008 06:45

Just adding a method which i wrote for an application for which the requirement was scrapped.
Hope someone can refer to this silly method. ;)

///
/// Method to sort an array of strings in descending order of number of words in each array element
///
///

Array to be sorted
/// Array sorted in descending order of number of words in each array element 
 

private static string[] SortArrayWithDescendingWordCount(string[] strArray)
{
//Array to store the number of words in each string of the array to be sorted
int[] wordLengths = new int[strArray.Length];
//variable to keep track of array index of wordLengths array.
int arrayIndex = 0;
foreach (string str in strArray)
{
//split the string in to an array of words and store the word count in wordLengths array.
wordLengths[arrayIndex] = str.Split(’ ‘).Length; ;
arrayIndex++;
}
//Sort arrays(ascending order) by taking wordLenths array as key and strArray as value
Array.Sort(wordLengths, strArray);
//now reverse strArray array to sort the array in descending order of number of words in each array element
Array.Reverse(strArray);
return strArray;
}

Tags: , , ,

Comments

4/28/2010 6:38:10 PM #

With LINQ you can do this in very concise way:

using System.Linq;
public string[] SortByDecendingWordCount(string[] listOfStatements)
        {
            var sorted = from c in listOfStatements
                         orderby c.Split(' ').Length descending
                         select c;

            return sorted.ToArray();


        }

Ashish India

4/28/2010 7:08:33 PM #

Thanks Ashish.. The above procedure was written much before Linq was released!

nishanth India

7/29/2010 9:46:20 AM #

//Sort arrays(ascending order) by taking wordLenths array as key and strArray as value
Array.Sort(wordLengths, strArray);

Please fix error here!

Pharmacie en ligne United States

8/11/2010 1:50:15 PM #

private static string[] SortArrayWithDescendingWordCount(string[] strArray)
{
//Array to store the number of words in each string of the array to be sorted
int[] wordLengths = new int[strArray.Length];
//variable to keep track of array index of wordLengths array.
int arrayIndex = 0;
foreach (string str in strArray)

Moslioen United States

9/5/2011 10:46:10 AM #

I sow a very good Mobile television

Michael Jefferson United States

9/26/2011 2:13:42 AM #

Hi,

Great Blog keep it up.
Buy i found a site were you can see any movie and tv show from all over the world no more \"Sorry, currently our video library can only be watched from your current location\"  Check it out at www.kewltv.net

Later People..

{Ron

10/27/2011 3:24:18 PM #

Wow , what an amazing blog. Keep up the nice work!

Get free TV on your phone now

11/19/2011 4:55:35 AM #

hello thanks for the info check out    my store

Andywills

11/19/2011 5:00:56 AM #

hello thanks for the info check out    my store

Andywills

12/8/2011 5:37:36 AM #

I appreciate and agree with many of your concerns about private/public projects. However, my experience has been less one-sided. It is my view that there are times when a private Corporation can make a profit and provide a better service. Private enterprise has to be innovative and cost-effective in order to stay in business. Government does not operate by the same principles and typically doesn't worry about going broke. There are some services that City employees do not handle as well as competitive businesses. City employees cannot be expected to be all things to all people. Of course, there are some services, such as policing and fire protection, that must be strictly controlled by the City, no matter the economics.

Jovan Joosten United States

12/11/2011 2:38:46 AM #

Instead, we would reference our lives from a collection of memories. Therefore, even more so than the act of breathing or consciousness, our lives are defined by thoughts, perceptions, and recollections of our experiences.

Maybell Mae United States

12/18/2011 2:05:51 PM #

Thanks for ones marvelous posting! I seriously enjoyed reading it, you happen to be a great author.I will be sure to bookmark your blog and definitely will come back later in life. I want to encourage that you continue your great posts, have a nice evening!
My spouse and I absolutely love your blog and find most of your post\'s to be exactly I\'m looking for. Does one offer guest writers to write content available for you? I wouldn\'t mind producing a post or elaborating on most of the subjects you write in relation to here. Again, awesome web site!
We stumbled over here  different page and thought I may as well check things out. I like what I see so now i am following you. Look forward to going over your web page repeatedly.
I like what you guys are up too. Such clever work and exposure! Keep up the wonderful works guys I\'ve incorporated

admin

12/23/2011 1:42:10 PM #

Hi
Great Blog , excellent content really loved reading
I would love to share your blog to my friends on Google Plus and  facebook.

Don

12/25/2011 11:28:24 PM #

Bad idea.<br />This is how you make money trading (anything). 1. Knowledge/skill 2. Inside information (illegal) and 3. Luck<br />You probably need at least two of those to be successul. How many have you got?<br />References :

Shana Sundseth United States

1/2/2012 6:20:48 PM #

Stuff related to infidelity, divorce along with other {types of|kinds of|forms of|sorts of|categories of relationships are generally under-reported in the papers.  It certainly could be helpful if more people continued with these sorts of conversations.

Reuben Alexakis United States

1/3/2012 1:53:14 AM #

Sustain superb work , I read few websites here but that the weblog is real intriguing and has got bands of fantastic info .

Hiram Hambric United States

1/7/2012 4:53:03 AM #

Nice article. last thirty days I uncovered this internet internet site and desired to permit you be conscious that i've been gratified, heading via your site's posts. I should certainly be signing equally as much as the RSS feed and should certainly wait around for another post. best Regards, Mateus

link building United States

1/16/2012 9:24:37 AM #

I need IE 6 for older apps. If I deactivate IE 8 and I try to install IE 6.... There is an newer version of this software...<br />O.K Microsoft sh.. happens.

Goldie Kristin United States

1/25/2012 1:57:42 PM #

These are awesome tips. It makes perfect sense to have the pitch done before you write the book. Wish I would have thought of that! I wrote the first draft of my query of the weekend, and thanks to some input from my critique partners, it's taking shape. Thanks for these great reminders.

chinese daily news United States

2/4/2012 2:44:52 AM #

When the movie Popeye was released a few years ago I marveled at how perfectly Williams and the rest of the cast translated the comic characters into live action. But my wife (a born American) and the rest of the nation hated it. Very sad. But I think translation from line comic drawing to full live action was too big a jump.<br />When I was a child I read Tintin and Asterix comics in French and Portuguese. That was about 50 years ago.<br />I went to see this movie (TinTin) despite your criticism, and found that it captured the spirit of Herge's art perfectly. I hope you are proved wrong. Perhaps the reverse of the Popeye movie will occur, and a new generation of Americans will discover the wonders of Herge's work, as I did.<br />Best Regards<br />Douglas<br />Marietta GA<br />01/14/12

Forest Deyon United States

Add comment




  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen


About Me

Nishanth Nair  

 A die hard fan of Rise of Nations... I write few softwares for McAfee Inc. for a living.

 

Portfolio:

http://morningbellnews.com
TheXorb.com
http://Necab.org
http://SufiKatha.com
http://DeepaRecipes.com
http://ManipalFoundation.in
http://NetraArts.com
http‌://EnWebTech.com 

http://homeopathyinchicago.com/


Contact : Nair.Nishanth@Gmail.com 

 

All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer.

Tag cloud

free counters