这个工具通常用来去除小说或者字幕中的广告。
比如以下一段文本:
BSTR实际上就是一个COM字符串,标准BSTR是一个有长度前缀和null结束符的OLECHAR数组。BSTR的前4字节是一个表示字符串长度的前缀。BSTR长度域的值是字符串的字节数,并且不包括0结束符
#include <comutil.h>
#include <string>
#pragma comment(lib, "comsuppw.lib")
//BSTR转string
BSTR bstrText = ::SysAllocString(L"Test");
string str = _com_util::ConvertBSTRToString(bstrText);
SysFreeString(bstrText);
//BSTR转char*
BSTR bstrText = ::SysAllocString(L"Test");
char* lpszText = _com_util::ConvertBSTRToString(bstrText);
SysFreeString(bstrText);
delete[] lpszText;
//char*转BSTR
char* lpszText = "Test";
BSTR bstrText = _com_util::ConvertStringToBSTR(lpszText);
//string转BSTR
string str = "Test";
BSTR bstrText = _com_util::ConvertStringToBSTR(str);
指定字符为“Str”,则包含Str的行都要去掉。
工具界面如图:
核心代码,很简单,判断字符串即可:
int CDllTestorDlg::ProceeOneFile(const _tstring& stFilePath, const _tstring& stToLookUp,const _tstring& stDstDir)
{
std::vector<_tstring> vContent, vContentNew;
size_t nLines = CStdFile::ParseTXTFile(stFilePath, vContent);
for (size_t j = 0; j < nLines; ++j)
{
_tstring stLine = vContent[j];
if ((m_cfg.bDelBlankLine && stLine.size() != 0 || !m_cfg.bDelBlankLine) && stLine.find(stToLookUp) == _tstring::npos)
{
vContentNew.push_back(stLine + _T('\n'));
}
}
_tstring stSavePath = stDstDir + CStdStr::GetNameOfFile(stFilePath);
CStdFile::SaveTXTFile(stSavePath, vContentNew);
return 0;
}
欢迎交流。