公众号:程序员崛起
这里不写完整的代码,说下大概的情况
场景:
有一个字符串类型为 wchar_t 类型,需要解析,
(1)将解析后的每个单元数据去除空格,
(2)判断是否仅有 ‘数字’\'.'、‘空格’,删除其中的空格;倘若不是纯数字则不去除空格;
思路:
如果看了上一篇博客,大概就知道我的思路,使用 CString 容器完成这些操作;
期间遇到一个奇怪的问题,就是当自己使用 wstring 使用 erase 无法删除(空格为 L‘ ’ ,如果有哪位大佬知道麻烦指教),最后转为 CString才能删除。
这个demo是解决第二个第一个屏蔽里面的if判断即可;
解析的数据格式:
@dwi oidehfeh@dk asjhj哦我的 大家 思 考@ 5 @
第一种目标数据:
dwioidehfehdkasjhj哦我的大家思考5
第二种目标数据:
dwi oidehfehdk asjhj哦我的 大家 思 考5
CString csReemSpace
void REMOVESPACE(CString doc)
{
CString csReemSpcetemp(doc.GetString());
csReemSpace = csReemSpcetemp;
if (doc.GetLength() != 0)
{
csReemSpace.Remove(L' ');
}
}
void mf(char *str)
{
int nNum = 0;
CString csRowInf(str);
wstring wsRowinf = csRowInf;
if (!wsRowinf.empty())
{
// 获取数据的个数
vector <int> vColumLen;
int VNLineNumber[256][50] = { 0 };
vector <wstring> vwsCellTexts;
vector <wstring> arryCellTexts;
int nDocSize = wsRowinf.find_last_of(_T('@')) + 1;
vColumLen.push_back(0);
int index = 1;
while (index < nDocSize)
{
//列的个数 vColumLen.size() - 1
if (wsRowinf.at(index) == _T('@'))
{
vColumLen.push_back(index);
}
index++;
}
index = 0;
for (index = 1; index < vColumLen.size(); index++)
{
// 解析后获取数据存入 arryCellTexts
arryCellTexts.push_back(wsRowinf.substr(vColumLen.at(index - 1) + 1, vColumLen.at(index) - vColumLen.at(index - 1) - 1).c_str());
// 是否只包含数字,是否为数字
REMOVESPACE(csReemSpace.GetString());
if (csReemSpace.SpanIncluding(L"0123456789.") == csReemSpace)
arryCellTexts[index - 1].Remove(L' ');
// mapXmlReport[nNumDoc].writeTextXml(arryCellTexts[index - 1].GetString(), pSet);
}
//if (bWrap != 0)
//{
//mapXmlReport[nNumDoc].writeTextXml(_T("\n"), NULL);
//}
nNum = arryCellTexts.size();
vColumLen.clear();
vwsCellTexts.clear();
arryCellTexts.clear();
}
}
这个东西让我思考以下的结果东西:
1、算法(比如数据结构、结构体)
2、STL就是容器,容器的好多作用自己还是不甚理解
3、协议(比如,经典的TCP协议、格式的定义和解析,自己在思考什么时候实现以下试试)