Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3878893
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2008-05-07 22:03:35

MSDN上的问题   自己做了下
 
例如如何从下面的html中提取所有的省份名称并自动存入数据库:
HTML code
cur.addBoard(new Board("CN","3078","四川")) cur.addBoard(new Board("CN","3256","天津")) cur.addBoard(new Board("CN","3290","西藏")) cur.addBoard(new Board("CN","3371","新疆")) cur.addBoard(new Board("CN","3478","浙江")) cur.addBoard(new Board("CN","3559","云南")) cur.addBoard(new Board("CN","1908","湖北")) cur.addBoard(new Board("CN","2258","江西")) cur.addBoard(new Board("CN","3262","重庆")) cur.addBoard(new Board("CN","2536","宁夏")) cur.addBoard(new Board("CN","2561","青海")) cur.addBoard(new Board("CN","2610","上海")) cur.addBoard(new Board("CN","2614","广东")) cur.addBoard(new Board("CN","2728","山西")) cur.addBoard(new Board("CN","2847","山东")) cur.addBoard(new Board("CN","1002","安徽")) cur.addBoard(new Board("CN","1098","北京")) cur.addBoard(new Board("CN","1103","福建")) cur.addBoard(new Board("CN","1181","甘肃")) cur.addBoard(new Board("CN","1277","广西")) cur.addBoard(new Board("CN","1382","贵州")) cur.addBoard(new Board("CN","1474","海南")) cur.addBoard(new Board("CN","1511","河北")) cur.addBoard(new Board("CN","1670","河南")) cur.addBoard(new Board("CN","1816","黑龙江")) cur.addBoard(new Board("CN","2002","湖南")) cur.addBoard(new Board("CN","2118","吉林")) cur.addBoard(new Board("CN","2177","江苏")) cur.addBoard(new Board("CN","2361","辽宁")) cur.addBoard(new Board("CN","2434","内蒙古"))
文件内容一行行读入CString中然后一个个查找
CString s;
size_t lpos = s.ReverseFind( ',' );  //0
size_t rpos = s.ReverseFind('\"' );  //5
s.Mid(lpos+1,rpos-lpos-2);

举个例子
C/C++ code
int main(int argc, char* argv[]) { CString src = ",\"内蒙古\"))"; size_t lpos = src.ReverseFind( ',' ); size_t rpos = src.ReverseFind('\"' ); CString des = src.Mid(lpos+2,rpos-lpos-2); ASSERT(0 == des.Compare("内蒙古")); cout << "OK\n"; return 0; }

输出 
OK
Press any key to continue

这样就找出来了
阅读(1862) | 评论(0) | 转发(0) |
0

上一篇:获得本机网卡ip

下一篇:操作符重载手册

给主人留下些什么吧!~~