[英]String comparison C++
我想在szDir
中检查szSelectedDir
。 我希望函数考虑以下输入内容。 我的示例函数未处理该场景,请让我知道好的解决方案。
string szSelectedDir ="C:\\Windows1\Test";
string szDir="C:\\Windows";
void IsWindowsDirectory(const string szSpecialPath, const string szSelectedPath)
{
if(szSelectedPath.compare(szSpecialPath) == 0)
{
printf("Both paths are same ");
}
else if(szSelectedPath.find(szSpecialPath) != string::npos)
{
printf("Both paths are same ");
}
else
{
printf("Both paths are different ");
}
}
在szDir
中检查szSelectedDir
。
if (szSelectedDir.find(szDir) != string::npos)
{
// You found szDir in szSelectedDir
}
就像已经说过的那样,比较C ++中的字符串非常简单...
if (szSelectedPath == szSpecialPath)
我建议您通过引用传递字符串(字符串不为null等等)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.