c++截取##内字符

/***********************************************************************
Functions:	Trim(string& sStr)
Purpose:	截去字符串两端的空格或TAB
Parameter:	sStr------------字符串
Return:		无
Usage:		#str="   China   ";
Trim(str);
#str="China";
************************************************************************/
void 	CMacSnStr::Trim(string& sStr)
{
	if (sStr.length() == 0){
		return;
	}
	string::iterator pos = sStr.end() - 1;
	for (; pos >= sStr.begin();){
		if (*pos == ' ' ||
			*pos == '\t' ||
			*pos == '\n' ||
			*pos == '\r'){
			sStr.erase(pos);
			pos = sStr.end() - 1;
		}
		else
			break;
	}

	pos = sStr.begin();
	for (; pos<sStr.end();){
		if (*pos == ' ' ||
			*pos == '\t' ||
			*pos == '\n' ||
			*pos == '\r'){
			sStr.erase(pos);
			pos = sStr.begin();
		}
		else
			break;
	}
}

int CMacSnStr::FindGV(const string strorig, string& strgv)
{
	char* cpBeginPos = NULL;
	char* cpEndPos = NULL;
	cpBeginPos = (char*)strchr(strorig.c_str(), '#');
	if (cpBeginPos != NULL)
		cpEndPos = strchr(cpBeginPos + 1, '#');

	if (cpBeginPos != NULL && cpEndPos != NULL){
		strgv = strorig.substr(cpBeginPos - strorig.c_str(), cpEndPos - cpBeginPos + 1);
		return 0;
	}
	else{
		return -1;
	}
}

  

posted @ 2021-10-22 10:41  xmydis  阅读(55)  评论(0)    收藏  举报