-2

I am not sure how to search for this, or I would. What I need to do is count up with letters rather than numbers. the input will only contain letters and numbers, no spaces, or dashes.

For example, if the user enters "A" for start and "ABC" for end it would output, A, B, C,...AA, AB, AC,...ABC.

I can do it by breaking everything down to an array, increase, the last index, until "Z", then, increase the index, check if it is equals end, then loop again.When "Z" is hit and it has a number (treated as a string) start to loop through "0 - 9".

It just seems there would be an easier way, than what I am thinking. I seen one solution in Java that I could convert, but not fully understanding how it works SO Post it is using MOD and does not really compare values. This is just a small project for a computer lab, to generate NetBIOS names, for another program to use. All the names are sequential.

Thanks,

Dave

Community
  • 1
  • 1
MaxThrust
  • 137
  • 2
  • 2
  • 9
  • 1
    Can you share the code you have? –  Dec 29 '16 at 19:59
  • 1
    The term you are searching for is "combinations". – Abion47 Dec 29 '16 at 19:59
  • 1
    so what are you trying to do? Can you give us example inputs and complete! expected output? – Hogan Dec 29 '16 at 20:00
  • 2
    something like this http://stackoverflow.com/questions/1011732/iterating-through-the-alphabet-c-sharp-a-caz –  Dec 29 '16 at 20:02
  • 1
    This is a base conversion problem. You need to convert from base10 to base26 and back using the alphabet as the symbols for the base26 output. The goal will be to find out what the start and end inputs are in base10, then iterate in base10, converting each iteration to base26 for output. – Jonathon Chase Dec 29 '16 at 20:12
  • Leok, I think that one may work. I have not written any of the code, since I was hoping for a shorter way to do it. I am going to do some testing on the post you linked to. – MaxThrust Dec 29 '16 at 20:13
  • OK, let me know –  Dec 29 '16 at 20:18
  • Abion47, this to me is not really combinations. a combination would be, given "ABC", the output would be "ACB", "CAB", "BAC"... Hogan, an input/output would be Start-LAB1A, End- LAB1ABC. So I the counting part would be "A" - "ABC". There is a static part, which I know how to pull, and check. – MaxThrust Dec 29 '16 at 20:20
  • Leok, that is what I need. It gives me a great start point, and can tweak it to better fit. If you can do an "answer", i will give you the credit. – MaxThrust Dec 29 '16 at 20:39

1 Answers1

-1
    Dim array1 As String() = {"a", "b", "c"}
    Dim array2 As String() = {"a", "b", "c"}

    Dim result = array1.SelectMany(Function(f) array2, Function(f, a) New With {Key .first = f, Key .second = a})

    Dim s As String = String.Empty
    For i As Integer = 0 To result.Count - 1
        s += result(i).first + result(i).second + " "
    Next

    MessageBox.Show(s)

output:

aa ab ac ba bb bc ca cb cc

I think this may be close to what you are after. Similar to a cross-join in SQL. This works in VB.Net but you can run a code converter

EDIT: (Ran through code converter (vb to c#), untested)

string[] array1 = {
    "a",
    "b",
    "c"
};
string[] array2 = {
    "a",
    "b",
    "c"
};

dynamic result = array1.SelectMany(f => array2, (f, a) => new {
    first = f,
    second = a
});

string s = string.Empty;
for (int i = 0; i <= result.Count - 1; i++) {
    s += result(i).first + result(i).second + " ";
}

MessageBox.Show(s);

//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================
Rhurac
  • 439
  • 4
  • 16