-5

How can I generate a string that contains a every 2 character combination of input ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

Output would be formatted like this:

00
01
02
03
04
05
06
07
08
09
0A
0B
0C
0D
...
2g
2h
2i
2j
2k
2l
2m
2n
2o
2p
2q
2r
2s
2t
2u
2v
2w
2x
2y
2z
30
31
32
33
34
35
36
37
38
39
3A
3B
3C

The total length of the output would be 3844 lines.

  • Hah and these are actually real links – nice touch @gilliduck but where's the downvote then? :) OP, don't take this to heart, but it would be nice to see what you have already attempted so that we can explain you in more detail the parts you didn't get right. – Siavas Jan 28 '19 at 00:20
  • I haven't attempted anything as I don't know how to start. I'm not looking for someone to do this for me, I'm just looking for someone to point me in the right direction. – microsocks Jan 28 '19 at 00:22
  • You can get some inspirations here https://stackoverflow.com/questions/33336540/how-to-use-linq-to-find-all-combinations-of-n-items-from-a-set-of-numbers – Anu Viswan Jan 28 '19 at 00:25
  • @Siavas actually I do a VTC instead of a downvote. I only downvote on ones that won't be closed and honestly, shy of a major edit, there is no way this won't get closed. – gilliduck Jan 28 '19 at 00:29
  • Welcome to StackOverflow, OP. Please see [ask] for tips on how to write a question that will attract quality answers. Feel free to take the [tour]. Don't be surprised if this question gets closed, but feel free to post another (perhaps including some code)! – John Wu Jan 28 '19 at 00:52

1 Answers1

-1

Create an array of all your characters and then do a nested foreach loop to generate each possible combination.

static void Main()
{
    IList<char> characters = new List<char> {'a', 'b', 'c', 'd', 'e', 'f', 'g', '1', '2', '3'};
    foreach (char c1 in characters)
    {
        foreach (char c2 in characters)
        {
            Console.WriteLine(new string(new[] {c1, c2}));
        }
    }
    Console.ReadKey(true);
}
mr.coffee
  • 962
  • 8
  • 22
  • Why was this down voted? – mr.coffee Jan 28 '19 at 00:45
  • 2
    One possible reason - there are plenty of similar questions and code/answer like this already exists: so post gets downvote for "this answer is not useful". – Alexei Levenkov Jan 28 '19 at 02:18
  • How is my answer not useful? I provided a working sample and the poster accepted it. – mr.coffee Jan 28 '19 at 02:21
  • It's not useful for the community because it's a duplicate. It's not useful for the OP because they should learn by doing their HW by themselves. Now they have a solution and learned nothing. –  Jan 28 '19 at 09:31