ziwez0
asked on
Next Letter ABCD..
Hi,
can someone please give me an example of how to go to the next letter...
Example if i passed a varaible of A
string strNextLetter = B
or if I passed a W
string strNextLetter = X
I dont really want to do a case statement as there must be a easier way?
can someone please give me an example of how to go to the next letter...
Example if i passed a varaible of A
string strNextLetter = B
or if I passed a W
string strNextLetter = X
I dont really want to do a case statement as there must be a easier way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Without going into a lot of detail, here is a simple way to do it. Of course, you will need to determine what you want to do when the Starting Character is "Z" or "z".
string strCurrentLetter = "B";
string strNextLetter = "";
string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXY Zabcdefghi jklmnopqrs tuvwxyz";
if (strCurrentLetter == "Z")
{
// Do something special here
}
else
{
if (strCurrentLetter == "z")
{
// Do something special here
}
else
{
// Find the position of the Current Letter within the Alphabet
int intPos = Alphabet.IndexOf(strCurren tLetter);
// Find the character at the next position
strNextLetter = Alphabet.Substring(intPos + 1,1);
}
}
string strCurrentLetter = "B";
string strNextLetter = "";
string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXY
if (strCurrentLetter == "Z")
{
// Do something special here
}
else
{
if (strCurrentLetter == "z")
{
// Do something special here
}
else
{
// Find the position of the Current Letter within the Alphabet
int intPos = Alphabet.IndexOf(strCurren
// Find the character at the next position
strNextLetter = Alphabet.Substring(intPos + 1,1);
}
}
In my example, you will need to include 'using System.Text' in the code.
Open in new window