如何从CString
中删除特定行?这一行包含:"要删除的行"。
例如,输入为:
Remove Specific'n'
Line to remove'n'
Line From 'n'
CString C++.
输出应该是:
Remove Specific'n'
Line From 'n'
CString C++.
尝试CString。
将查找"要删除的行"的方法替换为NULL。查看MSDN
您需要将内容逐行复制到除要删除的行外的其他新字符串中,然后再次将新字符串复制到旧字符串中
谢谢大家!方法就像Heena Goyal说的
CString oldString = _T("Remove Specific'n' Line to remove'n' Line From 'n' CString C++.");
CString auxString ;
CString newString =_T("");
for (int i = 0; i < oldString.GetLength(); i++)
{
if (oldString[i] == 'n' || i == oldString.GetLength()-1)
{
if( i == oldString.GetLength() - 1)
auxString += oldString[i];
if(auxString.Find("Line to remove") == -1)
{
newString += auxString +'n';
}
auxString = _T("");
}
else
{
if (oldString[i] != 'r')
auxString += oldString[i];
}
}
newString = newString.Left(newString.GetLength() -1);