Link to home
Start Free TrialLog in
Avatar of TrialUser
TrialUserFlag for Afghanistan

asked on

picking different combination of words from an array of words

I have a string for example : apple pink lotus baby pen paper red

i wan extract     6 words then 5 words 4 words 3 words 2 words then 1 word from this array.. for example: apple pink lotus baby pen paper
apple pink lotus baby pen red
apple pink lotus baby paper red

and so on....
apple pink lotus baby pen
...

apple
pink
lotus
baby pen

Please help thanks. If there is code in VB.net that will be great
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

I've implemented to get 6 random strings. Likewise write for other cases. Refer: http://www.techrepublic.com/article/working-with-random-numbers-in-net-applications/5663283
using System;
using System.IO;
using System.Xml.Linq;
using System.Xml;
using System.Collections;
using System.Collections.Specialized;

namespace TestApplication
{
    class Program
    {
        static void Main(string[] args)
        {

            

            string[] myStrings = new string[7];
            myStrings = "apple pink lotus baby pen paper red".Split(" ".ToCharArray());


            Random objRandom = new Random();
            StringCollection objCollection = new StringCollection();

            //To get 6 values randomly
            for (int i = 0; i < 6; )
            {
                int random = objRandom.Next(0, 7); 

                if (!objCollection.Contains(myStrings[random]))
                {
                    objCollection.Add(myStrings[random]);
                    i++;
                }

            }

            foreach(string s in objCollection)
              Console.WriteLine(s);

            Console.Read();

        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have asked the same question 3 times now!