如何判断角色是大写还是特殊 [英] How do I tell if a character is Capitalized or Special

查看:88
本文介绍了如何判断角色是大写还是特殊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么判断一个角色是:



资本化:ABCDEFGHIJKLMNOPQRSTUVWXYZ



特价:` 〜!@#$%^&*()_- + = {[}]:;?/<> | \

How do you tell if a character is:

Capitalized: ABCDEFGHIJKLMNOPQRSTUVWXYZ

Special: `~!@#$%^&*()_-+={[}]:;""?/<>|\

推荐答案

% ^&*()_- + = {[}]:;?/<> | \
%^&*()_-+={[}]:;""?/<>|\


请参阅: http://msdn.microsoft.com/en-us/library/system.char%28v=vs。 110%29.aspx [ ^ ]。



要检查大小写,您需要此功能:http://msdn.microsoft.com/en-us/library/system.char.islower(v= vs.110).aspx [ ^ ]。



另外,要注意fu nctions IsLetter IsPunctuation IsSeparator 等。使用它们只要有可能。



我真的不确定你只想要列出的字符和这个有限的字符集(为什么?没有这样的概念,特殊性格)。但如果这真的是你需要的,你可以使用

Please see: http://msdn.microsoft.com/en-us/library/system.char%28v=vs.110%29.aspx[^].

To check capitalization, you need this function: http://msdn.microsoft.com/en-us/library/system.char.islower(v=vs.110).aspx[^].

Also, pay attention for the functions IsLetter, IsPunctuation, IsSeparator, etc. Use them whenever possible.

I don't really sure you want only the characters you listed and this limited set of characters (why? there is no such concept, "special character"). But if this is really what you need, you can use
const string myCapitalLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string myPunctuationCharacters = @"`~!@#

%^& *()_- + = {[}]:;?/< ;> | \;

// ...

< span class =code-keyword> char characterToTest = // ...某个字符;

// ...

bool isMyCapitalLetter = myCapitalLetters.Contains(characterToTest);
bool isMyPunctuation = myPunctuationCharacters.Contains(characterToTest);
// ...
%^&*()_-+={[}]:;""?/<>|\"; // ... char characterToTest = // ... some character; // ... bool isMyCapitalLetter = myCapitalLetters.Contains(characterToTest); bool isMyPunctuation = myPunctuationCharacters.Contains(characterToTest); // ...





-SA


这篇关于如何判断角色是大写还是特殊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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