首页 > 学院 > 开发设计 > 正文

使用CString 的 SpanIncluding 函数判断字符串是否全为数字

2019-11-08 19:35:01
字体:
来源:转载
供稿:网友
BOOL IsDigital(LPCTSTR lpszSrc) { CString Src = lpszSrc; return (Src == Src.SpanIncluding( _T("0123456789" ) )); } //测试代码 VERIFY( IsDigital( _T("23456") ) ); VERIFY( IsDigital( _T("23ABC") ) ); if(str.SpanIncluding(_T("0123456789")) == str){ //is digit}

This method extracts characters from the string, starting with the first character, which are in the set of characters identified by lpszCharSet. If the first character of the string is not in the character set, then SpanIncluding returns an empty string. Otherwise, it returns a sequence of consecutive characters which are in the set.

CString SpanIncluding( LPCTSTR lpszCharSet ) const;

Parameters lpszCharSet Specifies a string interPReted as a set of characters. Return Value Returns a substring that contains characters in the string that are in lpszCharSet, beginning with the first character in the string and ending when a character is found in the string that is not in lpszCharSet. SpanIncluding returns an empty substring if the first character in the string is not in the specified set.


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表