模拟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);
}