Char.IsHex()在C# [英] Char.IsHex() in C#
本文介绍了Char.IsHex()在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从<一个继href="http://stackoverflow.com/questions/223832/check-a-string-to-see-if-all-characters-are-hexadecimal-values">this问题什么是写在C#中Char.IsHex()函数的最佳方式。到目前为止,我已经得到了这一点,但不喜欢它:
布尔CharIsHex(字符C){
C = Char.ToLower(C);
返程(Char.IsDigit(三)||ç=='一'||ç=='B'||ç=='C'||ç=='D'||ç=='E'|| ç=='F')
}
解决方案
从<一个href="http://stackoverflow.com/questions/223832/check-a-string-to-see-if-all-characters-are-hexadecimal-values#223854">my回答为您链接到的问题:
布尔is_hex_char =(C&GT; ='0'和;和C&LT; ='9')||
(C&GT; ='A'和;和C&LT; ='F')||
(C&GT; ='A'和;和C&LT; ='F');
Following on from this question what would be the best way to write a Char.IsHex() function in C#. So far I've got this but don't like it:
bool CharIsHex(char c) {
c = Char.ToLower(c);
return (Char.IsDigit(c) || c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f')
}
解决方案
From my answer to the question you linked to:
bool is_hex_char = (c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F');
这篇关于Char.IsHex()在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文