问一个用boost的正则表达式提取汉字的问题...

seadaughter 2008-11-28 09:39:07
我的代码如下:


#include <iostream>
#include <string>
#include <locale>
#include <boost/regex.hpp>
using namespace boost;
using namespace std;

wstring convert2wstr(string sToMatch)//将普通字符串转换为宽字符串
{
setlocale( LC_CTYPE, "zh_CN.gbk" );
int iWLen= mbstowcs( NULL, sToMatch.c_str(), sToMatch.length() );
wchar_t *lpwsz= new wchar_t[iWLen+1];
int i= mbstowcs( lpwsz, sToMatch.c_str(), sToMatch.length() );
wstring wsToMatch(lpwsz);
delete []lpwsz;
cout<<"i = "<<i<<endl;
return wsToMatch;
}

string wstr2str(wstring wsm)
{
int iLen= wcstombs( NULL, wsm.c_str(), 0 ); // 计算转换后字符串的长度。(不包含字符串结束符)
char *lpsz= new char[iLen+1];
int i= wcstombs( lpsz, wsm.c_str(), iLen ); // 转换。(没有结束符)
lpsz[iLen] = '\0';
string sToMatch(lpsz);
delete []lpsz;
return sToMatch;
}

int main()
{
string str="我:是 :中国人:民";
wstring ws=convert2wstr(str);
wregex expression(L"[\u4e00-\u9fa5]+");//提取所有汉字...

wsmatch what;
std::wstring::const_iterator start = ws.begin();
std::wstring::const_iterator end = ws.end();

while( boost::regex_search(start, end, what, expression) )
{
//这里面该写什么啊????
start = what[0].second;
}

return 1;
}



问问怎么不行了呢。。。怎么补充。。或者有别的更好大的代码没??谢谢啊。。
...全文
154 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
就呆在云上 2008-11-30
  • 打赏
  • 举报
回复
boost一般人很少用吧
因此这个东西就不好怎么弄了
seadaughter 2008-11-30
  • 打赏
  • 举报
回复
顶。。。
lzh9955 2008-11-30
  • 打赏
  • 举报
回复
顶一下
toadzw 2008-11-30
  • 打赏
  • 举报
回复
up to your climax
seadaughter 2008-11-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xhs_lh04 的回复:]
是不是应该这样[\x{4e00}-\x{9fa5}]

[/Quote]
貌似不对。。。你现场试一下。。。
xhs_lh04 2008-11-28
  • 打赏
  • 举报
回复
是不是应该这样[\x{4e00}-\x{9fa5}]
lc19890326 2008-11-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ztz0223 的回复:]
boost不懂
帮顶

[/Quote]
帮顶 还没钻研过boost
就呆在云上 2008-11-28
  • 打赏
  • 举报
回复
boost不懂
帮顶

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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