First, that's base 36, I believe.
Second, you can access a string by index and return a character, which can
be cast directly to an iteger.
To get the Unicode (rather than ASCII in .NET) value of the third character
of a string, for example, you would use:
string myString = "SOMESTRING";
int code = (int)myString[2];
Luckily, the basic alphabet has the same code points in Unicode as they do
in ASCII. Still, you may want to do subtraction from the char literal 'A'
to make the code more readable.
int result = 0;
int factor = 1;
for(int index = myString.Length; index >= 0; index--) {
int digitValue = 0;
char digit = myString[index];
if(Char.IsDigit(digit))
{
digitValue = (int)(digit) - (int)('0');
}
else if(Char.IsUpper(digit))
{
digitValue = 10 + (int)(digit) - (int)('A');
}
else if(Char.IsLower(digit))
{
digitValue = 10 + (int)(digit) - (int)('a');
}
result += factor * digitValue;
factor *= 36;
}
// result contains the converted number
I haven't tested that code, so you'll want to try it yourself and possibly
optimize it or make it your own. You might overflow an Int32 pretty quickly
so you may need to use 64-bit math.
--Matthew W. Jackson
"Tony Tortora" <AT@att.com> wrote in message
news:e%****************@TK2MSFTNGP11.phx.gbl...
I am writing and add on application. The application uses Unique IDs and
they are stored in Base 26 (ie 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ).
I am having trouble reading the decimal value of a character of the key
and to assign a the new value for the Unique ID.
For example to change "A" to "B". Normally, I would read the ASCII value
of "A" which is 65, add one making it 66 which is "B".
How can I do this is C#.
Thanks