现在想实现一个这样的功能,查找特定的一个dat文件中的是否存在某个关键字,比如我的dat文件下有这样一句话
Name=代
GivenName=启芬
MiddleName=
Birthdate=1963
我现在就想查找
Name=代
GivenName=启芬
两句,如果存在则提示查找成功,这样应该怎么实现,有没有相关的代码,谢谢各位了
Name=代
GivenName=启芬
MiddleName=
Birthdate=1963
我现在就想查找
Name=代
GivenName=启芬
两句,如果存在则提示查找成功,这样应该怎么实现,有没有相关的代码,谢谢各位了
不过,我怎么感觉你这个有点像配置文件呀!
CString strTemp;while ( file.ReadString(strTemp))
{
// find something
if(strTemp.Find("name=".0) != -1)
{
// name existing
}
}
char aa[100];
temp1.SeekToBegin();
temp1.Read(aa,temp1.GetLength());
AfxMessageBox(aa);
CString sss;
int ol=0;
file.Open("C:\\Documents and Settings\\Administrator\\桌面\\代_启芬\\Patient.dat",CFile::modeRead);
while(file.ReadString(sss))
{
ol++;
if(ol>0)
break;
}
AfxMessageBox(sss);这样读TXT就是没问题,但是读dat就会是乱码
temp1.Open(_T("C:\\Documents and Settings\\Administrator\\桌面\\代_启芬\\Patient.dat"),CFile::modeReadWrite);
char aa[100];
temp1.SeekToBegin();
temp1.Read(aa,temp1.GetLength());
AfxMessageBox(aa);好奇怪
temp1.Open(_T("C:\\Documents and Settings\\Administrator\\桌面\\代_启芬\\Patient.dat"),CFile::modeCreate|CFile::modeReadWrite);
wchar_t aa[100];
temp1.SeekToBegin();
memset(aa, 0, 200);
int rl = temp1.Read(aa, 50);
char bb[200];
count = wcstombs(bb, aa, 200);
AfxMessageBox(bb);
然后强行转换为wchar *
有人可以帮我解答么,是不是编码出问题了,这个dat是公司以前的技术写的,也找不到他人了,不知道用的什么编码,我把用文本打开,用UltraEdit打开的图片都放上面了,大家帮我研究下看看,怎样可以还原出来,麻烦麻烦了
TCHAR *Ansi2Unicode(char *psz,TCHAR *pwsz)
{
int iLen = strlen(psz);
MultiByteToWideChar(CP_ACP,0,psz,-1,pwsz,iLen+1);
return pwsz;
}char *Unicode2Ansi(TCHAR *pwsz,char *psz)
{
int ansiLen = WideCharToMultiByte(CP_ACP,NULL,pwsz,wcslen(pwsz),NULL,NULL,NULL,NULL);
WideCharToMultiByte(CP_ACP,NULL,pwsz,wcslen(pwsz),psz,ansiLen,NULL,NULL);
return psz;
}通过字符转换试一下
用16进制查看就知道了.
{
int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL );
if (nLen == 0)
{
return NULL;
}
char* pResult = new char[nLen];
WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL );
return pResult;
}但是前后有乱码,第一个字和最后一个是乱码
跳过前面两个字节再读取.