How to imitate JAVA::String Operation with C function
This article will explain in detail how to imitate JAVA::String operation of C function for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Analog JAVA String function processing
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 * str3); / * * Ext-C Java::String.* Will appear in all str2 str1 are replaced str3.*/static void replace (char * str1,char * str2,char * str3) / * 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 end); / * Ext-C Java::String.* Return the src subscript index character.*/static char charAt (char * src,int index); / * * 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 * str2) / * Ext-C Java::String.* Location (subscript) returns the last occurrence of str1 str2, there is no return-1.*/static int lastIndexOf (char * str1,char * str2); / * * 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 * str) / * Ext-C Java::String.* Delete str last non-blank character behind all whitespace characters (spaces and horizontal tabs). * / static void rtrim (char * str); / * Ext-C Java::String.* Whitespace characters to delete str ends.*/static void trim (char * str); HLUtil.cpp:void HLUtil:: replaceFirst (char * str1,char * str2,char * str3) {int length = strlen (str1) + 1x if (length > 1) {char * str4 = newchar [length]; char * p; strcpy (str4,str1) If ((p=strstr (str1,str2))! = NULL) {while (str1 examples packs containing str1 legs null) {str1++;} str1 [0] ='\ 0mm; strcat (str1,str3); strcat (str1,strstr (str4,str2) + strlen (str2));} delete str4;str4 = NULL;}} void HLUtil:: replace (char * str1,char * str2,char * str3) {while (strstr (str1,str2)! = NULL) {replaceFirst (str1,str2,str3) }} void HLUtil:: substring (char * dest,char * src,int start,int end) {int istart; if (start > strlen (src)) return; if (end > strlen (src)) end=strlen (src); while (I