Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get nth letter of english alphabet

Is there any way to get nth letter of English alphabet? I want smt similar to this:

string letter = EnglishAlphabet.GetLetter(5);
//result -> letter is 'E'

I want to use this according to count of my list. If there is 3 elements on my list so "D:D" is enough for me but there is 4 elements then "E:E". I want use this string here:

 Excel.Range chartRange;    
 Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
 Excel.ChartObject myChart = xlCharts.Add(5, 5, 540, 160);
 Excel.Chart chartPage = myChart.Chart;    
 chartRange = xlWorkSheet.get_Range("A:A", "D:D");//"D:D" changes according to size of the list??

Any suggestions? Thanks

like image 891
cihadakt Avatar asked Jan 02 '14 12:01

cihadakt


People also ask

How do you get the nth letter of the alphabet in Python?

Use the string module to print the Nth letter of the alphabet, e.g. print(string. ascii_lowercase[2]) . The ascii_lowercase attribute returns a string containing the lowercase ASCII letters, so we can access the string at index N.

What is the number of alphabet?

The English Alphabet consists of 26 letters: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z.


1 Answers

The simplest approach is:

public string GetLetter(int value)
{
    char letter = (char) ('A' - 1 + value);
    return letter.ToString();
}

I'd personally change the return type to char though:

public char GetLetter(int value)
{
    return (char) ('A' - 1 + value);
}

You might want to put some argument validation on there too though...

like image 76
Jon Skeet Avatar answered Oct 09 '22 22:10

Jon Skeet