当前位置: 首页>>代码示例>>C++>>正文


C++ string_type::substr方法代码示例

本文整理汇总了C++中string_type::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ string_type::substr方法的具体用法?C++ string_type::substr怎么用?C++ string_type::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string_type的用法示例。


在下文中一共展示了string_type::substr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: julian_no_leap

    //! Julian day. Feb29 is never counted, even in leap years
    // expects range of 1-365
    void julian_no_leap(const string_type& s, const string_type& e){
      typedef gregorian::gregorian_calendar calendar;
      const unsigned short year = 2001; // Non-leap year
      unsigned short sm=1;
      int sd=0;
      sd = lexical_cast<int>(s.substr(1)); // skip 'J'
      while(sd >= calendar::end_of_month_day(year,sm)){
        sd -= calendar::end_of_month_day(year,sm++);
      }
      unsigned short em=1;
      int ed=0;
      ed = lexical_cast<int>(e.substr(1)); // skip 'J'
      while(ed > calendar::end_of_month_day(year,em)){
        ed -= calendar::end_of_month_day(year,em++);
      }

      dst_calc_rules_ = shared_ptr<dst_calc_rule>(
        new partial_date_dst_rule(
          partial_date_dst_rule::start_rule(
            sd, static_cast<date_time::months_of_year>(sm)),
          partial_date_dst_rule::end_rule(
            ed, static_cast<date_time::months_of_year>(em))
          )
      );
    }
开发者ID:,项目名称:,代码行数:27,代码来源:

示例2: parse_format

 void parse_format(const string_type & format_str) {
     typedef typename string_type::size_type size_type;
     size_type msg_idx = format_str.find('%');
     if ( msg_idx != string_type::npos) {
         m_prefix = format_str.substr(0, msg_idx);
         m_suffix = format_str.substr( msg_idx + 1);
     }
     else
         // no suffix
         m_prefix = format_str; 
 }
开发者ID:ST3ALth,项目名称:libed2k,代码行数:11,代码来源:spacer.hpp

示例3: format

    /** @brief sets the format string: what should be before, and what after the original message, separated by "|"

    Example: \n
    "[%idx%] |\n" - this writes "[%idx%] " before the message, and "\n" after the message

    If "|" is not present, the whole message is prepended to the message
    */
    void format(const string_type & format_str) {
        m_format_str = format_str;

        typename string_type::size_type idx = format_str.find('|');
        string_type before, after;
        if ( idx != string_type::npos) {
            before = format_str.substr(0, idx);
            after = format_str.substr(idx + 1);
        }
        else
            before = format_str;

        format( before, after);
    };
开发者ID:gbucknell,项目名称:fsc-sdk,代码行数:21,代码来源:named_write.hpp

示例4: extract

            void extract( string_type const & data, string_type & name, string_type & value, basic_cookie<Tag> & c )
            {
                std::size_t pos = data.find( string_traits_type::convert('=') );
                name = data.substr( 0,pos );
                if ( pos != string_type::npos )
                {
                    value = data.substr( pos+1 );
                }

                if ( !value.empty() )
                {
                    if ( *value.begin() == '"' && *value.rbegin() != '"' )
                    {
                        value = name + string_traits_type::convert("=") + value;
                        return;
                    }
                    boost::trim_if( value, boost::is_any_of( string_traits_type::convert("\"") ) );
                }
                set_value( name, value, c );
                name.clear();
                value.clear();
            }
开发者ID:vinzenz,项目名称:libomvtk,代码行数:22,代码来源:cookie_parser.hpp

示例5: BYTE_ConvertFromHexStringToArray

int CCommonFnc::BYTE_ConvertFromHexStringToArray(string_type hexaString, BYTE* pArray, DWORD* pbArrayLen) {
    int         status = STAT_OK;
    DWORD       pos = 0;
    DWORD       pos2 = 0;
	string_type     hexNum;
    DWORD       num;
    BYTE*       pTempArray = NULL;
    DWORD       tempArrayPos = 0;

    // EAT SPACES
    //hexaString.TrimLeft(); hexaString.TrimRight();
	hexaString.erase(hexaString.find_last_not_of(_CONV(" ")) + 1);
	size_t startpos = hexaString.find_first_not_of(_CONV(" "));
	if (string_type::npos != startpos) {
		hexaString = hexaString.substr(startpos);
	}
    hexaString += _CONV(" ");
    hexaString.length();

    if (status == STAT_OK) {
        pTempArray = new BYTE[hexaString.length()];
        memset(pTempArray, 0, hexaString.length());

        pos = pos2 = 0;
        /*while ((pos = hexaString.Find(' ', pos2)) != -1) {
            hexNum = hexaString.Mid(pos2, pos - pos2);
            hexNum.TrimLeft(); hexNum.TrimRight();
            if (hexNum.GetLength() > 0) {
                num = strtol((LPCTSTR) hexNum, NULL, 16);
        
                if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF;
                else pTempArray[tempArrayPos] = (BYTE) num & 0xFF;
                
                tempArrayPos++;
            }
            pos2 = pos + 1;
        }*/
		while ((pos = hexaString.find(' ', pos2)) != string_type::npos) {
			hexNum = hexaString.substr((pos2, pos - pos2));
			hexNum.erase(hexNum.find_last_not_of(_CONV(" ")) + 1);
			size_t startpos2 = hexNum.find_first_not_of(_CONV(" "));
			if (string_type::npos != startpos2) {
				hexNum = hexNum.substr(startpos2);
			}
			if (hexNum.length() > 0) {
				num = type_to_int((LPCTSTR)hexNum.c_str(), NULL, 16);

				if (num == 0xFF) pTempArray[tempArrayPos] = 0xFF;
				else pTempArray[tempArrayPos] = (BYTE)num & 0xFF;

				tempArrayPos++;
			}
			pos2 = pos + 1;
		}

        if (tempArrayPos > *pbArrayLen) {
            status = STAT_NOT_ENOUGHT_MEMORY;
        }  
        else {
            memcpy(pArray, pTempArray, tempArrayPos);
        }
        *pbArrayLen = tempArrayPos;

        if (pTempArray) delete[] pTempArray;
    }

    return status;
}
开发者ID:,项目名称:,代码行数:68,代码来源:


注:本文中的string_type::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。