Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I want to make program where i would generate all possible combinations if i have on 4 places and in first 3 places there is sign and at the 4th place is number. And to it will write it in notepad. Any idea how i can start with this?
Posted
Comments
Pradeep Shukla 18-Sep-11 12:44pm    
Are you trying to generate a string of length 4 in which first 3 are alphabets and 4th is a numeric ?

You can nest for-loops and have them iterate through the desired characters like this:
C#
for (char symbol1 = 'a'; symbol1 <= 'z'; symbol1++)
{
    for (char symbol2 = 'a'; symbol2 <= 'z'; symbol2++)
    {

    }
}

and if You wish to print to a text file:
C#
StreamWriter output = new StreamWriter("output.txt");
output.WriteLine("Hello! This is the first line in my text file.");
output.WriteLine("And this is the second one.");
output.Close();

don't forget to call output.Close() or output.Flush() to make sure that the text is written to the file before your program terminates

or simply use:
C#
File.WriteAllText("output.txt", "Hello!");

You will need to add "using System.IO;" at the top of your program
 
Share this answer
 
ADD this at the begining:

using System.IO;


StreamWriter sw = new StreamWriter("File name.txt");


for (char symbol1 = 'a'; symbol1 <= 'z'; symbol1++)

    for (char symbol2 = 'a'; symbol2 <= 'z'; symbol2++)

         for (char symbol3 = 'a'; symbol2 <= 'z'; symbol2++)

            for (int num = 0; num <= 10; num++)

                 sw.WriteLine("{},{},{},{}",symbol1,symbol2,symbol3,num );
                 sw.close();



Good Luck :)
 
Share this answer
 
v2
It might be helpful,

C#
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int counter = -1;

        using (StreamWriter writer = new StreamWriter(@"C:\Temp\DataFile.txt", true))
        {
            Array.ForEach(GetData(), item =>
            {
                if (counter >= 9) counter = -1;
                writer.WriteLine(string.Concat(item, item, item, ++counter));
            });
        }
    }

    static char[] GetData()
    {
        return Enumerable.Range('a', ('z' - 'a') + 1).Select(c => (char)c).ToArray();
    }
}


:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900