void RegisterLayer::editBoxReturn(CCEditBox* editBox)
{
// 安全检查~
if (!editBox)
{
return;
}
string text = editBox->getText();
if (text.length() <= 0)
{
return;
}
// 过滤非法字符~
stringstream strStream;
for (int i = 0; i < text.length(); i ++)
{
unsigned char ch = text.at(i);
if ((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9'))
{
strStream << ch;
}
}
string strResult = strStream.str();
editBox->setText(strResult.c_str());
}editBox 过滤特定字符
最新推荐文章于 2025-04-23 11:05:30 发布
本文介绍了一个用于处理EditBox返回值的函数,该函数通过过滤非法字符确保只允许字母和数字输入。通过对用户输入的字符串进行逐字符检查并使用stringstream重新构建有效字符组成的字符串。
5999

被折叠的 条评论
为什么被折叠?



