ホーム » 2015 » 11月 » 19

日別アーカイブ: 2015/11/19

2015年11月
1234567
891011121314
15161718192021
22232425262728
2930  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,447 アクセス



vector -> tstring

以前 MFC を使用した StringArrayToString を変更したが,今回は STL 版.


tstring String_Join (const std::vector<tstring>& srcAry,LPCTSTR sp)
{
  tstring str ;
  for (size_t index= 0 ; index<srcAry.size() ; index++) {
    str += srcAry[index] ;
    if (index+1 == srcAry.size()) { continue ; }
    str += sp ;
    }
  return str ;
  }
MFC 版は VC 6 までだったが,STL 版では VC 7 も遅い.


tstring String_Join (const std::vector<tstring>& srcAry,LPCTSTR sp)
{
  tstring str ;
  v_tstring tmpSA ;
  tstring tmpStr ;
  for (size_t index= 0 ; index<srcAry.size() ; index++) {
    tmpStr += srcAry[index] ;
    if (index+1 == srcAry.size()) { continue ; }
    if ((index%128) == 100) {
      tmpSA.push_back(tmpStr) ;
      tmpStr.erase() ;
      continue ;
      }
    tmpStr += sp ;
    }
  if (!tmpStr.empty()) {
    tmpSA.push_back(tmpStr) ;
    }
  if (tmpSA.size() > 1) {
    str = ::String_Join(tmpSA,sp) ;
    }
  else if (tmpSA.size() == 1) {
    str = tmpSA[0] ;
    }
  return str ;
  }

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.