转换字符到其字母表整数位置? [英] Convert character to its alphabet integer position?

查看:147
本文介绍了转换字符到其字母表整数位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到,如果有一个快速的方式来获得在字母表(C#)字符的整数位置。

I'm trying to find if there is a quick way to get the integer position of a character in the alphabet (C#).

我可以简单地创建一个阵列和得到的位置,但似乎必须有acheiving本的漂亮和时髦的方式?

I can simply create an array and get the position, but seems there must be a "nice and funky" way of acheiving this?

我也看了采取的ASCII码位置( !大写)字符相对于65......但同样,似乎比它应该是更多的工作。

I've also looked at taking the ASCII position of the (uppercase) character in relation to "65"...but again, seems more work than it should be!

[英语只有26个字母组成的字母表,不需要国际化 - 与不,这不是功课]

[English 26 letter alphabet only, no internationalisation required - and no, this is not homework!]

推荐答案

编程101:

char c = 'A';
//char c = 'b'; you may use lower case character.
int index = char.ToUpper(c) - 64;//index == 1

这篇关于转换字符到其字母表整数位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆