字符串搜索问题

rg1982 2007-10-24 09:45:57
我现在有个文件,我读取
source="1";
source="2";
...
r="1";
a="2";
..
想在其中搜到source 找到后面的"1","2".希望给位大侠提供思路,说明一下。谢谢
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jlspwangcaihong 2007-10-26
  • 打赏
  • 举报
回复
在WriteIni的时候可以用个循环将它写成
Source1=“1”
Source2=“2”
凤矶 2007-10-25
  • 打赏
  • 举报
回复
UP
---------------------------


发表于:2007-10-25 01:42:49
--------------------------
楼上牛人哪!
aa65433 2007-10-25
  • 打赏
  • 举报
回复
如果是一行一行的且格式固定就用
CStdioFile.ReadString(tmp)读取一行
int itemp=tmp.Find("source=");
tmp=tmp.Right(tmp.GetLength()-itemp);//获得"1"
tmp=tmp.left(tmp.GetLength()-1);
tmp=tmp.Right(tmp.GetLength()-1);

rg1982 2007-10-25
  • 打赏
  • 举报
回复
zzz3265 那么做是有问题的,当你读到第一个Source=的时候你是读了后面的,但是将
source="2";
...
r="1";
a="2";
..
也读出来了。而我只是想得到“1”
rg1982 2007-10-25
  • 打赏
  • 举报
回复
CHAR *pFileData = GetFileData();
CHAR *pFind;

pFind = strstr(pFileData , "source=\"");
pFind += strlen("source=\"");
int n1 = atoi(pFind);

pFind = strstr(pFind , "source=\"");
pFind += strlen("source=\"");
int n2 = atoi(pFind);
我现在把文件读取的结果放在CHAR* pBuf中的pBuf里,是不是就把pFind = strstr(pFileData , "source=\""); 改为
pFind = strstr(pBuf, "source=\"");但是改完,编译没问题,执行不行啊。
一楼的,我也想用GetPrivateProfileString来读但是,文件里键名有重复,只能读第一个啊,所以我才选择文件查询的。
Yofoo 2007-10-25
  • 打赏
  • 举报
回复
CHAR *pFileData = GetFileData();
CHAR *pFind;

pFind = strstr(pFileData , "source=\"");
pFind += strlen("source=\"");
int n1 = atoi(pFind);

pFind = strstr(pFind , "source=\"");
pFind += strlen("source=\"");
int n2 = atoi(pFind);

ReverseEngineering 2007-10-24
  • 打赏
  • 举报
回复
问题没搞懂,

一般来说就是逐个字符比较。
yiyiyi888888 2007-10-24
  • 打赏
  • 举报
回复
用ini配置文件
用GetPrivateProfileString读

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧