Avatar of jxbma
Flag for United States of America

asked on 

What is a good method for incrementing a string sequence from "A" to "ZZZZ" in C# or vb.Net?


I have an interesting problem I need to solve.
I'm sure that someone has encountered this somewhere
and that an elegant solution exists.

I'm trying to write an method which increments and returns the next
alphanumeric character in a sequence.

These letters are intended to range from 'A' to 'ZZZZ'.
I am only dealing with capital (uppercase letters)

Consider the following examples:

    INPUT        OUTPUT
    A            B
    G            H
    Z            AA
    AZ          BA
    AZZZ      BAAA

Open in new window

I'm looking for a solution which is more or less portable across
languages (C#, VB.Net, JavaScript/JQuery). This of course rules out
trying something with LINQ.

I've made several attempts at this, but the all are kind of klunky.
Any thoughts, ideas, suggestions or directions to explore would be greatly appreciated.

C#Visual Basic.NETJavaScriptjQueryAlgorithms

Avatar of undefined
Last Comment

8/22/2022 - Mon