Wednesday, November 25, 2009

AlphaNumeric Series

http://www.codeproject.com/KB/recipes/AlphaNumeric_Increment.aspx
Many alpha numeric samples increment only numeric part and append alpha as prefix, but the requirement was to increment all characters in a series.
This is usually required if you want to generate some unique varchar value for a database, or to achieve more combination in short length.
Numeric 0-9 (Length 2) = 100 combinations
Numeric A-Z (Length 2) = 676 combinations
Numeric 0-9A-Z (Length 2) = 1296 combinations
Also it should have modes to control series generation direction.

public enum SequenceType
{
/// 00,01,...,09,0A,...0Z,10,11...,A0,A1,...,ZZ
NumericToAlpha = 1,

/// AA,AB,...,AZ,A0,...A9,BA,BB...ZZ,00,01,...99
AlphaToNumeric = 2,

/// A0,A1,...,A9,AA,...AZ,B0,B1...ZZ,00,01,...99
AlphaNumeric = 3,

/// 00,01,...99
NumericOnly = 4,

/// AA,AB,...,ZZ
AlphaOnly = 5
}

No comments:

Post a Comment