how to get nth letter of english alphabet

喜欢而已 提交于 2019-12-23 18:22:42

问题


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


回答1:


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...




回答2:


In Excel: =CHAR(64+A1) where A1 contains the value of n may suit.



来源:https://stackoverflow.com/questions/20882656/how-to-get-nth-letter-of-english-alphabet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!