C++之$find和$contian

阅读: 评论:0

C++之$find和$contian

C++之$find和$contian

对字符串的常用操作有从指定位置找特定子串位置。还有判断字符串是否包含字串。这次包装 f i n d 和 find和 find和contian方法如下。并修复了发现的之前函数的bug。

头文件

#pragma onece
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;///用C++实现M常用操作字符串方法$改doler///判断字符串里是否包含字串
///source:源串
///childStr:子串
bool dolercontian(string source,string childStr);///在字符串里从指定位置查找特定字符串位置,没找到返回-1
///source:源串
///childStr:子串
///startIndex:开始查找位置
///num:查找第几个
int dolerfind(string source,string childStr,int startIndex=0,int num=1);///给字符串剔除左边的空格
///retStr:返回串
///source:源串
void dolertrimleft(string &retStr,string source);///给字符串剔除右边的空格
///retStr:返回串
///source:源串
void dolertrimright(string &retStr,string source);///给字符串剔除两边的空格
///retStr:返回串
///source:源串
void dolertrim(string &retStr,string source);///用给定的字符串替换字符串里的指定字符串
///retStr:返回串
///source:源串
///orgStr:要替换的串
///repStr:替换的串
void dolerreplace(string &retStr,string source,string orgStr,string repStr);///按指定字符串分割字符串取指定位置
///retStr:返回串
///source:源串
///split:分割串
///index:位置,按M习惯从1开始
void dolerp(string &retStr,string source,string split,int index);///按指定字符串分割字符串返回向量
///retvec:返回向量
///source:源串
///split:分割串
void dolersplit(vector<string> &retvec,string source,string split);///按指定字符串分割字符串的长度
///source:源串
///split:分割串
int dolerl(string source,string split);

cpp实现

#include "mutil.h"//判断字符串里是否包含字串
///source:源串
///childStr:子串
bool dolercontian(string source,string childStr)
{//源串为空返回假if(source==""){return false;}//子串为空返回假if(childStr==""){return false;}if(dolerfind(source,childStr)>-1){return true;}else{return false;}}///在字符串里从指定位置查找特定字符串位置,没找到返回-1
///source:源串
///childStr:子串
///startIndex:开始查找位置
///num:查找第几个
int dolerfind(string source,string childStr,int startIndex,int num)
{//源串为空返回-1if(source==""){return -1;}//子串为空返回-1if(childStr==""){return -1;}int sourceLen=source.length();int childLen=childStr.length();//开始位置加字串长度大于原串长度也返回-1if(startIndex+childLen>=sourceLen){return -1;}int ret=-1;int curFindNum=0;for(int i=startIndex+childLen-1;i<sourceLen;i++){//当前位置大于等于分割串长度,且当前字符等于分割串最后一位就比前面字符if(source[i]==childStr[childLen-1]){//时候和分割串相同bool isCommon=true;for(int j=0;j<childLen;j++){if(source[i-j]!=childStr[childLen-1-j]){isCommon=false;break;}}if(isCommon==true){curFindNum++;ret=i-childLen+1;i+=childLen;}if(curFindNum==num){break;}}}return ret;
}///给字符串剔除左边的空格
///retStr:返回串
///source:源串
void dolertrimleft(string &retStr,string source)
{string retStrTmp="";//源串为空返回空if(source==""){retStr=retStrTmp;return;}int sourceLen=source.length();int startIndex=-1;for(int i=0;i<sourceLen;i++){char one=source[i];if(one!=' '){startIndex=i;break;}}//全部是空格if(startIndex==-1){retStr=retStrTmp;return;}retStrTmp=source.substr(startIndex,sourceLen-startIndex);retStr=retStrTmp;
}///给字符串剔除右边的空格
///retStr:返回串
///source:源串
void dolertrimright(string &retStr,string source)
{string retStrTmp="";//源串为空返回空if(source==""){retStr=retStrTmp;return;}int sourceLen=source.length();int endIndex=-1;for(int i=sourceLen-1;i>=0;i--){char one=source[i];if(one!=' '){endIndex=i;break;}}//全部是空格if(endIndex==-1){retStr=retStrTmp;return;}retStrTmp=source.substr(0,endIndex+1);retStr=retStrTmp;
}///给字符串剔除两边的空格
///retStr:返回串
///source:源串
void dolertrim(string &retStr,string source)
{string tmpstr;dolertrimleft(tmpstr,source);dolertrimright(retStr,tmpstr);
}///用给定的字符串替换字符串里的指定字符串
///retStr:返回串
///source:源串
///orgStr:要替换的串
///repStr:替换的串
void dolerreplace(string &retStr,string source,string orgStr,string repStr)
{string retStrTmp="";//源串为空返回空if(source==""){retStr=retStrTmp;return;}//要替换的串为空返回空if(orgStr==""){retStrTmp=source;retStr=retStrTmp;return;}int sourceLen=source.length();int orgLen=orgStr.length();int curIndex=0;int startIndex=0;//遍历找到按分割串分割的指定位数的串for(int i=0;i<sourceLen;i++){//当前位置大于等于分割串长度,且当前字符等于分割串最后一位就比前面字符if(i>=orgLen&&source[i]==orgStr[orgLen-1]){//时候和分割串相同bool isCommon=true;for(int j=0;j<orgLen;j++){if(source[i-j]!=orgStr[orgLen-1-j]){isCommon=false;break;}}if(isCommon==true){curIndex++;int len=i-orgLen-startIndex+1;if(curIndex>1){retStrTmp+=repStr+source.substr(startIndex,len);}else{retStrTmp=source.substr(startIndex,len);}startIndex=i+1;i+=orgLen;}}}if(startIndex<sourceLen){if(curIndex>1){retStrTmp+=repStr+source.substr(startIndex,sourceLen-startIndex);}else{retStrTmp=source.substr(startIndex,sourceLen-startIndex);}}retStr=retStrTmp;
}///按指定字符串分割字符串取指定位置
///retStr:返回串
///source:源串
///split:分割串
///index:位置,按M习惯从1开始
void dolerp(string &retStr,string source,string split,int index)
{string retStrTmp="";//源串为空返回空if(source==""){retStr=retStrTmp;return;}//分割串为空返回空if(split==""){retStr=retStrTmp;return;}//位置不合格返回空if(index<1){retStr=retStrTmp;return;}int sourceLen=source.length();//源串为空返回空if(sourceLen==0){retStr=retStrTmp;return;}int spLen=split.length();//分割串为空返回空if(spLen==0){retStr=retStrTmp;return;}int curIndex=0;int startIndex=0;int endIndex=0;//遍历找到按分割串分割的指定位数的串for(int i=0;i<sourceLen;i++){//当前位置大于等于分割串长度,且当前字符等于分割串最后一位就比前面字符if(i>=spLen&&source[i]==split[spLen-1]){//时候和分割串相同bool isCommon=true;for(int j=0;j<spLen;j++){if(source[i-j]!=split[spLen-1-j]){isCommon=false;break;}}if(isCommon==true){curIndex++;if(curIndex==index){endIndex=i-spLen;break;}if(curIndex==index-1){startIndex=i+1;}i+=spLen;}}}//不包含子串返回源串if(curIndex==0&&index==1){retStrTmp=source;retStr=retStrTmp;return;}//没有取的位数返回空else if(curIndex<index-1){retStr=retStrTmp;return;}else{if(startIndex>endIndex){endIndex=sourceLen-1;}int retArrLen=endIndex-startIndex+1;char retArr[retArrLen];for(int k=startIndex;k<=endIndex;k++){retStrTmp+=source[k];}retStr=retStrTmp;return;}
}///按指定字符串分割字符串的长度
///source:源串
///split:分割串
int dolerl(string source,string split)
{int ret=1;//源串为空返回空if(source==""){return ret;}//分割串为空返回空if(split==""){return ret;}int sourceLen=source.length();//源串为空返回空if(sourceLen==0){return ret;}int spLen=split.length();//分割串为空返回空if(spLen==0){return ret;}int curIndex=0;int startIndex=0;int endIndex=0;//遍历找到按分割串分割的指定位数的串for(int i=0;i<sourceLen;i++){//当前位置大于等于分割串长度,且当前字符等于分割串最后一位就比前面字符if(i>=spLen&&source[i]==split[spLen-1]){//时候和分割串相同bool isCommon=true;for(int j=0;j<spLen;j++){if(source[i-j]!=split[spLen-1-j]){isCommon=false;break;}}if(isCommon==true){ret++;i+=spLen;}}}return ret;
}///按指定字符串分割字符串返回向量
///retvec:返回向量
///source:源串
///split:分割串
void dolersplit(vector<string> &retvec,string source,string split)
{retvec.clear();//源串为空返回空if(source==""){return;}//分割串为空返回空if(split==""){return;}int sourceLen=source.length();//源串为空返回空if(sourceLen==0){return;}int spLen=split.length();//分割串为空返回空if(spLen==0){return;}int curIndex=0;int startIndex=0;int endIndex=0;//遍历找到按分割串分割的指定位数的串for(int i=0;i<sourceLen;i++){//当前位置大于等于分割串长度,且当前字符等于分割串最后一位就比前面字符if(i>=spLen&&source[i]==split[spLen-1]){//时候和分割串相同bool isCommon=true;for(int j=0;j<spLen;j++){if(source[i-j]!=split[spLen-1-j]){isCommon=false;break;}}if(isCommon==true){int len=i-spLen-startIndex+1;retvec.push_back(source.substr(startIndex,len));startIndex=i;i+=spLen;}}}if(startIndex<sourceLen){retvec.push_back(source.substr(startIndex,sourceLen-startIndex));}
}

测试cpp

#include "mutil.h"
///测试
int main(int argc, char* argv[])
{string all="张三^29岁^男^433127199101211234";string sp="^";string ret;//测试分割取子串cout<<endl;cout<<"测试分割取子串*********************"<<endl;dolerp(ret,all,sp,1);cout<<"第一位为:"<<ret<<endl;dolerp(ret,all,sp,2);cout<<"第二位为:"<<ret<<endl;dolerp(ret,all,sp,3);cout<<"第三位为:"<<ret<<endl;dolerp(ret,all,sp,4);cout<<"第四位为:"<<ret<<endl;dolerp(ret,all,"29",2);cout<<"29分割第二位为:"<<ret<<endl;dolerp(ret,all,"298",2);cout<<"298分割第二位为:"<<ret<<endl;dolerp(ret,all,"433",1);cout<<"433分割第一位为:"<<ret<<endl;//测试分割向量cout<<endl;cout<<"测试分割向量*********************"<<endl;vector<string> vecarr;dolersplit(vecarr,all,sp);for(int i=0;i<vecarr.size();i++){cout<<"数组第"<<i<<"位为:"<<vecarr[i]<<endl;}//测试分割得到长度cout<<endl;cout<<"测试分割得到长度*********************"<<endl;int len=dolerl(all,sp);cout<<"长度为:"<<len<<endl;for(int i=1;i<=len;i++){string childStr;dolerp(childStr,all,sp,i);cout<<"取第"<<i<<"个字串:"<<childStr<<endl;}//测试替换字符串cout<<endl;cout<<"测试替换字符串*********************"<<endl;string allrepstr="张三^29岁^男^433127199101211234";string repret;dolerreplace(repret,allrepstr,"^","$@$");cout<<allrepstr<<",替换:^"<<"为:$@$得到:"<<repret<<endl;string repret1;repret="张三$@$29岁$@$男$@$433127199101211234";dolerreplace(repret1,repret,"$@$","%ZSP%");cout<<repret<<",替换:$@$"<<"为:%ZSP%得到:"<<repret1<<endl;//测试替换字符串//测试剔除空格cout<<endl;cout<<"测试剔除空格*********************"<<endl;string hasSpaceStr="   张三 男 29岁  ";string trimRet;dolertrimleft(trimRet,hasSpaceStr);cout<<"去除左空格:"<<trimRet<<endl;dolertrimright(trimRet,hasSpaceStr);cout<<"去除右空格:"<<trimRet<<endl;dolertrim(trimRet,hasSpaceStr);cout<<"去除两边空格:"<<trimRet<<endl;//测试剔除空格//测试查找子串位置cout<<endl;cout<<"测试查找子串位置*********************"<<endl;string allfindstr="张三^29岁^男^433127199101211234";cout<<"原串:"<<allfindstr<<endl;int firstFind=dolerfind(allfindstr,"^");cout<<"第一个^在:"<<firstFind<<endl;int secondFind=dolerfind(allfindstr,"^",3,2);cout<<"从第四个开始第二个^在:"<<secondFind<<endl;int mutiFind=dolerfind(allfindstr,"^男^");cout<<"^男^位置为:"<<mutiFind<<endl;//测试查找子串位置//测试包含字串cout<<endl;cout<<"测试包含字串*********************"<<endl;bool isContain=dolercontian(allfindstr,"^");cout<<allfindstr<<"是否包含^结果为:"<<isContain<<endl;isContain=dolercontian(allfindstr,"^男^");cout<<allfindstr<<"是否包含^男^结果为:"<<isContain<<endl;isContain=dolercontian(allfindstr,"@A@");cout<<allfindstr<<"是否包含@A@结果为:"<<isContain<<endl;//测试包含字串return 0;
}

cmake

# : mutil 的 CMake 项目,在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.8)project ("mutil")# 将源代码添加到此项目的可执行文件。
add_executable (mutil "mutil.cpp" "mutil.h" "main.cpp") # TODO: 如有需要,请添加测试并安装目标。

调试测试过程

[zhanglianzhu@zlzlinux ~]$ cd /zlz/mutil
[zhanglianzhu@zlzlinux mutil]$ ll
总用量 104
-rw-rw-r-- 1 zhanglianzhu zhanglianzhu 13675 3月  13 18:
drwxrwxr-x 5 zhanglianzhu zhanglianzhu   230 3月  15 20:58 CMakeFiles
-rw-rw-r-- 1 zhanglianzhu zhanglianzhu  1590 3月  13 18:51 ake
-rw-r--r-- 1 zhanglianzhu zhanglianzhu   345 3月  14 19:
-rw-rw-r-- 1 zhanglianzhu zhanglianzhu  2771 3月  16 20:00 main.cpp
-rw-rw-r-- 1 zhanglianzhu zhanglianzhu  5646 3月  14 19:58 Makefile
-rwxrwxr-x 1 zhanglianzhu zhanglianzhu 50576 3月  15 20:58 mutil
-rw-rw-r-- 1 zhanglianzhu zhanglianzhu 10140 3月  16 19:55 mutil.cpp
-rw-rw-r-- 1 zhanglianzhu zhanglianzhu  1503 3月  16 19:58 mutil.h
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
/zlz/mutil/mutil.cpp:8:71: 错误:为‘int dolerfind(std::__cxx11::string, std::__cxx11::string, int, int)’的第 3 个形参指定了默认实参 [-fpermissive]int dolerfind(string source,string childStr,int startIndex=0,int num=1)^
In file included from /zlz/mutil/mutil.cpp:1:
/zlz/mutil/mutil.h:14:5: 附注:previous specification in ‘int dolerfind(std::__cxx11::string, std::__cxx11::string, int, int)’ hereint dolerfind(string source,string childStr,int startIndex=0,int num=1);^~~~~~~~~
/zlz/mutil/mutil.cpp:8:71: 错误:为‘int dolerfind(std::__cxx11::string, std::__cxx11::string, int, int)’的第 4 个形参指定了默认实参 [-fpermissive]int dolerfind(string source,string childStr,int startIndex=0,int num=1)^
In file included from /zlz/mutil/mutil.cpp:1:
/zlz/mutil/mutil.h:14:5: 附注:previous specification in ‘int dolerfind(std::__cxx11::string, std::__cxx11::string, int, int)’ hereint dolerfind(string source,string childStr,int startIndex=0,int num=1);^~~~~~~~~
make[2]: *** [CMakeFiles/mutil.dir/build.make:76:CMakeFiles/mutil.dir/mutil.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:83:CMakeFiles/mutil.dir/all] 错误 2
make: *** [Makefile:91:all] 错误 2
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
[ 66%] Building CXX object CMakeFiles/mutil.dir/main.cpp.o
[100%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
第一个^在:5
从第四个开始第二个^在:11
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
[ 66%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
第一个^在:6
从第四个开始第二个^在:12
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
[ 66%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
第一个^在:5
从第四个开始第二个^在:11
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
[ 66%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
aa1�
aa2�
aa3�
aa4�
aa5�
aa6^
第一个^在:5
aa4�
aa5�
aa6^
aa89
aa9�
aa10�
aa11�
aa12^
从第四个开始第二个^在:11
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
[ 66%] Building CXX object CMakeFiles/mutil.dir/main.cpp.o
[100%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
第一个^在:6
从第四个开始第二个^在:12测试包含字串*********************
张三^29岁^男^433127199101211234是否包含^结果为:1
张三^29岁^男^433127199101211234是否包含^男^结果为:0
张三^29岁^男^433127199101211234是否包含@A@结果为:0
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/main.cpp.o
[ 66%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
第一个^在:6
从第四个开始第二个^在:12
^男^位置为:-1测试包含字串*********************
张三^29岁^男^433127199101211234是否包含^结果为:1
张三^29岁^男^433127199101211234是否包含^男^结果为:0
张三^29岁^男^433127199101211234是否包含@A@结果为:0
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
[ 66%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
第一个^在:6
从第四个开始第二个^在:12
^男^位置为:-1测试包含字串*********************
张三^29岁^男^433127199101211234是否包含^结果为:1
张三^29岁^男^433127199101211234是否包含^男^结果为:0
张三^29岁^男^433127199101211234是否包含@A@结果为:0
[zhanglianzhu@zlzlinux mutil]$ make
Consolidate compiler generated dependencies of target mutil
[ 33%] Building CXX object CMakeFiles/mutil.dir/mutil.cpp.o
[ 66%] Linking CXX executable mutil
[100%] Built target mutil
[zhanglianzhu@zlzlinux mutil]$ ./mutil测试分割取子串*********************
第一位为:张三
第二位为:29岁
第三位为:男
第四位为:433127199101211234
29分割第二位为:岁^男^433127199101211234
298分割第二位为:
433分割第一位为:张三^29岁^男^测试分割向量*********************
数组第0位为:张三
数组第1位为:^29岁
数组第2位为:^男
数组第3位为:^433127199101211234测试分割得到长度*********************
长度为:4
取第1个字串:张三
取第2个字串:29岁
取第3个字串:男
取第4个字串:433127199101211234测试替换字符串*********************
张三^29岁^男^433127199101211234,替换:^为:$@$得到:张三$@$29岁$@$男$@$433127199101211234
张三$@$29岁$@$男$@$433127199101211234,替换:$@$为:%ZSP%得到:张三%ZSP%29岁%ZSP%男%ZSP%433127199101211234测试剔除空格*********************
去除左空格:张三 男 29岁  
去除右空格:   张三 男 29岁
去除两边空格:张三 男 29岁测试查找子串位置*********************
原串:张三^29岁^男^433127199101211234
第一个^在:6
从第四个开始第二个^在:12
^男^位置为:12测试包含字串*********************
张三^29岁^男^433127199101211234是否包含^结果为:1
张三^29岁^男^433127199101211234是否包含^男^结果为:1
张三^29岁^男^433127199101211234是否包含@A@结果为:0
[zhanglianzhu@zlzlinux mutil]$ 

本文发布于:2024-02-02 00:34:08,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170681067240237.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:C++之dolerp($p)
标签:find   contian
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23