首页 > 编程知识 正文

判断字符是不是字母的函数,isalpha怎么判断字母Python

时间:2023-05-06 14:15:00 阅读:273421 作者:1537

今天刚学会了一个函数用来判断一个字符串中的字符是否为字母,函数名为isalpha,具体内容为下:

测试一个元素来包装区域设置是字母字符。

以带有颜色区分的格式查看 复制到剪贴板 template<Class CharType> bool isalpha( CharType _Ch, const locale& _Loc ) template<Class CharType> bool isalpha( CharType _Ch, const locale& _Loc ) 参数
_Ch

元素是测试。

_Loc

包含字母的元素的区域设置进行测试。

返回值

true,则测试的元素为字母为; false,则不是。

备注

模板函数 use_facet< ctype<返回 CharType> >(_Loc)。 是( ctype< CharType>或 alpha,_Ch)。

示例
以带有颜色区分的格式查看 复制到剪贴板 // locale_isalpha.cpp// compile with: /EHsc#include <locale>#include <iostream>using namespace std;int main( ) { locale loc ( "German_Germany" ); bool result1 = isalpha ( 'L', loc); bool result2 = isalpha ( '@', loc); bool result3 = isalpha ( '3', loc); if ( result1 ) cout << "The character 'L' in the locale is " << "alphabetic." << endl; else cout << "The character 'L' in the locale is " << " not alphabetic." << endl; if ( result2 ) cout << "The character '@' in the locale is " << "alphabetic." << endl; else cout << "The character '@' in the locale is " << " not alphabetic." << endl; if ( result3 ) cout << "The character '3' in the locale is " << "alphabetic." << endl; else cout << "The character '3' in the locale is " << " not alphabetic." << endl;} // locale_isalpha.cpp// compile with: /EHsc#include <locale>#include <iostream>using namespace std;int main( ) { locale loc ( "German_Germany" ); bool result1 = isalpha ( 'L', loc); bool result2 = isalpha ( '@', loc); bool result3 = isalpha ( '3', loc); if ( result1 ) cout << "The character 'L' in the locale is " << "alphabetic." << endl; else cout << "The character 'L' in the locale is " << " not alphabetic." << endl; if ( result2 ) cout << "The character '@' in the locale is " << "alphabetic." << endl; else cout << "The character '@' in the locale is " << " not alphabetic." << endl; if ( result3 ) cout << "The character '3' in the locale is " << "alphabetic." << endl; else cout << "The character '3' in the locale is " << " not alphabetic." << endl;} Output
以带有颜色区分的格式查看 复制到剪贴板 The character 'L' in the locale is alphabetic.The character '@' in the locale is not alphabetic.The character '3' in the locale is not alphabetic. The character 'L' in the locale is alphabetic.The character '@' in the locale is not alphabetic.The character '3' in the locale is not alphabetic. 要求

页眉: <区域设置>

命名空间: std


版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。