2018/06/06

Boost Regex and Unicode in C++ Builder

Boost - Bast C++ Library
Because "String" default is unicode in C++ Builer 2009 later.

And same std::wstring.

so, We should to use prefix "w" class, like:
wregex, wsmatch etc.

The Sample code below:




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 //#include <boost/regex.hpp>
 std::wstring line;
 //line = Edit1->Text.c_str();
 line = String(u"ようこそ456").c_str();
 std::wstring text;
 //boost::wregex regExp(Edit2->Text.c_str());
 boost::wregex regExp(String(u"56").c_str());
 boost::wsmatch what;
 if (boost::regex_search(line, what, regExp)) {
  text = std::wstring(what[0].first, what[0].second);
  ShowMessage(text.c_str());
 }




See also:

沒有留言:

張貼留言