如何从CString
删除特定行?此行包含:"要删除的行"。
例如,输入为:
Remove Specific'\n'
Line to remove'\n'
Line From '\n'
CString C++.
输出应为:
Remove Specific'\n'
Line From '\n'
CString C++.
答案 0 :(得分:1)
尝试使用CString.Replace方法查找"要删除的行"并替换为NULL。
检查MSDN
答案 1 :(得分:0)
您需要逐行将内容复制到除要删除的行之外的其他新字符串,然后再将旧字符串复制到旧字符串中。
答案 2 :(得分:0)
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);