Cocos2d-x 字符串查找:如何判断字符串中是否包含特定字符
在 Cocos2d-x 中,可以使用字符串的 find 函数来查找一个字符是否存在。你可以按照下面的方式来查找字符串中是否包含字符'2':
std::string str = '123';
if (str.find('2') != std::string::npos) {
// '2' found in the string
CCLOG('Found 2 in the string');
} else {
// '2' not found in the string
CCLOG('2 not found in the string');
}
在上面的代码中,使用了 find 函数来查找字符串中是否包含字符'2'。如果找到了字符'2',则 find 函数会返回字符的索引位置,否则返回 std::string::npos。因此,我们可以判断返回值是否等于 std::string::npos 来确定字符是否存在于字符串中。
原文地址: https://www.cveoy.top/t/topic/wip 著作权归作者所有。请勿转载和采集!