Skip to content

String handling functions

Function name function
StringCat Joint two character strings
StringCompare Compare the values of two character strings; case sensitive
StringCompareNoCase Compare the values of two character strings; case insensitive
StringCopy String copy
StringFind Return to the position of the first occurrence of target string in the source string; if there is no found in the source string, return to -1.
StringFindOneOf Return to the position of the first character in the source string that matches any character in target string; if there is no found in the source string, return to -1.
StringIncluding Retrieve a substring of the source string that contains characters in the set string.
StringInsert Insert a string into a specific position within the destination string content.
StringLength Obtain the length of a string.
StringMid Retrieve some characters sequence from the specified offset of the source string.
StringSplit Split out the string.
StringToLower Convert the characters of a string to lowercase.
StringToUpper Convert the characters of a string to uppercase.
StringTrim Split the source2 out from source1 to form a new one with the rest.
StringTrimLeft Split out any character of source2 in source1; Return the result to the dest.

1、StringCat

[Description]

Append source string to destination string.

[Usage]

result=StringCat(dest[start],source);

[Example]

char a[8]="abcd";
char *b="efg";
char *c;
c=StringCat(a,b); // c="abcdefg",it is better if a is a character array.

2、StringCompare

[Description]

Do a case-sensitive comparison of two strings.

[Usage]

result = StringCompare(source1,source2);

[Example]

int result;
char *a="abcd";
char *b="efg";
result = StringCompare(a,b); //result=-1(if a>b, result=1;if a=b, result=0; if a<b then result=-1)。

3、StringCompareNoCase //

[Description]

Do a case-insensitive comparison of two strings.

[Usage]

result = StringCompareNoCase(source1,source2)

[Example]

int result;
char *a="abcd";
char *b="EFG";
result=StringCompare(a,b);//result=1;
result=StringCompareNoCase(a,b);//result=-1;

4、StringCopy

[Description]

Copy ons string to another.

[Usage]

result = StringCopy(dest,source);

[Example]

char a[4]="abcd";
char* b="efg";
char* c;
c=StringCopy(a,b);//c="abcdefg"; it is better if a is a character array.

5、StringFind

[Description]

Return the position of the first occurrence of target string in the source string.

[Usage]

index=StringFind(source1,source2);

[Example]

char a[8]="ab1c123d";
char* b="123";
char* c="ef";
int index;
index=StringFind(a,b); //index=4;
index=StringFind(a,c); //index=-1;

6、StringFindOneOf

[Description]

Return the position of the first character in the source string that matches any character in target string.

[Usage]

index=StringFindOneOf(source1,source2);

[Example]

char a[8]="ab1c123d";

cahr* b="1b";

in index;

index=StringFindOneOf(a,b); //index=2;

7、StringIncluding

[Description]

Retrieve a substring of the source string that contains characters in the set string.

[Usage]

StringIncluding(source1,source2,dest);

[Example]

char a[8]="aB1Eree";
char* b="aBe";
char dest[8];
StringIncluding(a,b,dest);//dest="aBee"; it is better if dest is a character array.

8、StringInsert

[Description]

Insert a string in a specific within the destination string content. Notice it that the destination string has sufficient buffer.

[Usage]

StringInsert(pos,source,dest);

[Example]

char a[8] = "aB1e";
char *b ="kdr";
int pos=2;
StringInsert(pos,b,a); //a="aBkdr1e".

9、StringLength

[Description]

Obtain the length of a string.

[Usage]

result = StringLength(source);

[Example]

char a[8]="ABerer";
int length;
length = StringLength(a); //length=6;

10、StringMid

[Description]

Retrieve some characters sequence from the specified offset of the source string and store it in the destination buffer.

[Usage]

StringMid(source,count,dest);

[Example]

char a[8]="aB1e";
char b[3];
StringMid(a,2,b); //b="B1" it is better if b is a character array and it has enough memory to save the fetched character.

11、StringSplit

[Description]

Split out the string.

[Usage]

StringSplit(dest1,dest2,source,pos);

[Example]

char a[8]="aB1edge";
char b[5];
char c[5];
StringSplit(b,c,a,3); // it is better if b and c are character arrays.

12、StringToLower

[Description]

Convert the characters of a string to lowercase.

[Usage]

StringToLower(source,dest); // it is better if dest is a character array.

[Example]

char a[8]="ABeRe";
char b[8];
StringToLower(a,b);//b="abere".

13、StringToUpper

[Description]

Convert the characters of a string to uppercase.Notice if there is sufficient buffer.

[Usage]

StringToUpper(source,dest);

[Example]

char a[8]="ab1ere";
char b[8]; // it is better if b is a character array.
StringToUpper(a,b); //b="AB1ERE";

14、StringTrim

[Description]

split the source2 out from source1,return the result to dest.

[Usage]

StringTrim(source1.source2,dest);

[Example]

char a[12]="a1erd1esw";
char *b="1e";
char c[10];
StringTrim(a,b,c) //c="ardsw" . It is better if c is a character array.

15、StringTrimLeft

[Description]

split out any character of source2 in source1,Return the result to the dest.

[Usage]

StringTrimLeft(source1,source2,dest);

[Example]

char a[8]="aB1edge";
char* b="be";
char c[8];
StringTrimLeft(a,b,c);//c="aB1dg", It is better if c is a character array.