字符串包含有效字符
我正在编写一个方法,其签名是
bool isValidString(std::string value)
在该方法内我想搜索 value
中的所有字符都属于一组字符,该字符是常量字符串
const std::string ValidCharacters("abcd")
要执行此搜索,我从 中获取一个字符>value
并在 ValidCharacters
中搜索,如果此检查失败,那么它是无效字符串,STL 库中是否有其他替代方法可以执行此检查。
I am writing a method whose signature is
bool isValidString(std::string value)
Inside this method I want to search all the characters in value
are belongs to a set of characters which is a constant string
const std::string ValidCharacters("abcd")
To perform this search I take one character from value
and search in ValidCharacters
,if this check fails then it is invalid string is there any other alternative method in STL library to do this check.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
find_first_not_of()
:Use
find_first_not_of()
:您可以使用正则表达式进行模式匹配。
将包含库 regexp.h
http://www.digitalmars.com/rtl/regexp。 html
you can use regular expressions to pattern match.
library regexp.h is to be included
http://www.digitalmars.com/rtl/regexp.html