Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert letter to number 2

Status
Not open for further replies.

scottydd

IS-IT--Management
Sep 19, 2002
31
0
0
US
I was wondering if someone can help me with this problem?

I am getting a value from a datareader. This value is a letter. What i need to do is take this letter and increment it up by 1 letter (i.e. if the letter is a A I need to increment it to a B). Is there anyway I can do this using C#?

Any help would be appreciated...
Thanks,
Scott
 
internal char GetCharPlus1(char a)
{
char[] alp = {'a','b','c'.........};
char c = char.ToLower(a);
int i = alp.IndexOf(c);
if (i < 0) return Convert.ToChar(0);
// What is Z + 1??????
if (c = 'z') return Convert.ToByte(0);
return alp[i + 1];
}

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Argh

Try
internal char GetAlpP1(char a)
{
string alp = @"abcdef....";
char c = char.ToLower(a);
int i = alp.IndexOf(c);
if (i < 0) return Convert.ToChar(0);
if (c == 'z') return Convert.ToChar(0);
return alp[i + 1];
}

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Code:
public string getNextLetter (string letter)
{
    return ((char)((Byte)letter[0]+1)).ToString();
}

you need to write a statement that says what to return if Z or z is passed as argument

you can pass a string as argument but only the first letter will be taken into consideration

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Thanks for all your help, got what i needed

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top