模拟JAVA String 函数处理
HLUtil.h
/**
* Ext-C Java::String.
* replaceFirst Str1 string will replace the first occurrence of the string str2 into str3.
*/
static void replaceFirst(char *str1,char *str2,char
/**
* Ext-C Java::String.
* Will appear in all str2 str1 are replaced str3.
*/
static void replace(char *str1,char *str2,char
/**
* Ext-C Java::String.
* Src string interception, labeled start from the beginning to the end-1 (end front) of the string stored in dest (index starts at 0).
*/
static void substring(char *dest,char *src,int start,int
/**
* Ext-C Java::String.
* Return the src subscript index character.
*/
static char charAt(char *src,int
/**
* Ext-C Java::String.
* Return the position of the first occurrence of str2 (The following table index) in str1, there is no return -1.
*/
static int indexOf(char *str1,char
/**
* Ext-C Java::String.
* Location (subscript) returns the last occurrence of str1 str2, there is no return -1.
*/
static int lastIndexOf(char *str1,char
/**
* Ext-C Java::String.
* Remove the first non-blank character in front of the left str whitespace characters (spaces and horizontal tabs).
*/
static void ltrim(char
/**
* Ext-C Java::String.
* Delete str last non-blank character behind all whitespace characters (spaces and horizontal tabs).
*/
static void rtrim(char
/**
* Ext-C Java::String.
* Whitespace characters to delete str ends.
*/
static void trim(char
HLUtil.cpp:
void HLUtil:: replaceFirst(char *str1,char *str2,char
{
int
if(length>1)
{
char *str4 =new char[length];
char
strcpy(str4,str1);
if((p=strstr(str1,str2))!=NULL)
{
while(str1!=p&&str1!=NULL)
{
str1++;
}
str1[0]='\0';
strcat(str1,str3);
strcat(str1,strstr(str4,str2)+strlen(str2));
}
delete
str4 = NULL;
}
}
void HLUtil:: replace(char *str1,char *str2,char
{
while(strstr(str1,str2)!=NULL)
{
replaceFirst(str1,str2,str3);
}
}
void HLUtil:: substring(char *dest,char *src,int start,int
{
int
if(start>strlen(src))return;
if(end>strlen(src))
end=strlen(src);
while(i<end)
{
dest[i-start]=src[i];
i++;
}
dest[i-start]='\0';
return;
}
char HLUtil:: charAt(char *src,int
{
char
int
if(index<0||index>strlen(src))
return
while(i<index)i++;
return
}
int HLUtil:: indexOf(char *str1,char
{
char
int
p=strstr(str1,str2);
if(p==NULL)
return
else{
while(str1!=p)
{
str1++;
i++;
}
}
return
}
int HLUtil:: lastIndexOf(char *str1,char
{
char
int
p=strstr(str1,str2);
if(p==NULL)return
while(p!=NULL)
{
for(;str1!=p;str1++)i++;
p=p+len;
p=strstr(p,str2);
}
return i;
}
void HLUtil:: ltrim(char
{
int
while(str[i]!='\0')
{
if(str[i]!=32&&str[i]!=9)break;
i++;
}
if(i!=0)
for(j=0;j<=len-i;j++)
{
str[j]=str[j+i];
}
}
void HLUtil:: rtrim(char
{
char
int
while(i>=0)
{
if(p[i]!=32&&p[i]!=9)break;
i--;
}
str[++i]='\0';
}
void HLUtil:: trim(char
{
ltrim(str);
rtrim(str);
}
C函数仿写 JAVA::String操作
原创JsonKaitiren 博主文章分类:JAVA String ©著作权
©著作权归作者所有:来自51CTO博客作者JsonKaitiren的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:Cocos2dx 3.0 交流篇
下一篇:Xcode SVN配置方法
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C++仿函数
的数字的数量,你的代码很可能是这样的:#include <iostream>using ...
C++仿函数 仿函数 全局变量 函数指针 -
C++仿函数(函数对象)
仿函数(函数对象)研究set/multiset容器的排序原理。当我们构造一个存放int类型的set容器
c++ 函数对象 回调函数 仿函数 -
C++逻辑仿函数
逻辑仿函数功能描述:实现逻辑运算函数原型:template<class T> bool logical_and<T> //逻辑与template<class T> bool logical_or<T> //
c++ 逻辑仿函数 #include 仿函数 内建函数 -
C++之仿函数
仿函数:函数对象;仿函数(functors)其实就是重载了operator()的对象){
仿函数 #include ios -
C++关系仿函数
关系仿函数功能描述:实现关系对比仿函数原型:template<class T> bool equal_to<T> //等于template<class
c++ 关系仿函数 #include 仿函数 内建函数 -
C++之仿函数简介
概述仿函数(Functor)又称为函数对象(Function Object)
仿函数 .net 函数调用