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
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.
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With