c++ string 常用封装

#include <iostream>
#include <sstream>

bool replace(std::string& str, const std::string& from, const std::string& to) {
    size_t start_pos = str.find(from);
    if(start_pos == std::string::npos)
        return false;
    str.replace(start_pos, from.length(), to);
    return true;
}

std::string Lcase(std::string& str)
{
    int i;
    std::string temp = "";
    for(i = 0; i < str.length(); i++){
        temp += tolower(str[i]);
    }
    return temp;
}

std::string Ucase(std::string& str)
{
    int i;
    std::string temp = "";
    for(i = 0; i < str.length(); i++){
        temp += toupper(str[i]);
    }
    return temp;
}

std::string Mid(std::string& str, int pos1, int pos2)
{
    int i;
    std::string temp = "";
    for(i = pos1; i < pos2; i++){
        temp += str[i];
    }

    return temp;
}

std::string Left(std::string& str, int pos)
{
    int i;
    std::string temp = "";
    for(i = 0; i < pos; i++){
        temp += str[i];
    }

    return temp;
}

std::string Right(std::string& str, int pos)
{
    int i;
    std::string temp = "";
    for(i = pos; i < strlen(str.c_str()); i++)
    {
        temp += str[i];
    }
    return temp;
}

std::string joinString( const std::string & str, const std::vector< std::string > & seq )
{
	std::vector< std::string >::size_type seqlen = seq.size(), i;

	if ( seqlen == 0 ) return "";
	if ( seqlen == 1 ) return seq[0];

	std::string result( seq[0] );
	for ( i = 1; i < seqlen; ++i )
		result += str + seq[i];

	return result;
}

void splitString(const std::string& s,std::vector<std::string>& sv,const char delim = ' ') 
{
	sv.clear();
	std::istringstream iss(s);
	std::string temp;

	while (std::getline(iss, temp, delim)) 
		sv.emplace_back(std::move(temp));
	
	return;
}

//
void main()
{
    std::vector<std::string> sv;

	splitString(strValue.GetBuffer(), sv, ',');

	string su = joinString(",", sv);
	int a = 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值