17. cstring: comparenocase
Int comparenocase (lpctstr lpsz) const;
Return Value: returns 0, less than lpsz returns-1, greater than lpsz returns 1, not size characters
18. cstring: collate
Int collate (lpctstr lpsz) const;
Same as cstring: Compare
19. cstring: collatenocase
Int collatenocase (lpctstr lpsz) const;
Same as cstring: comparenocase
20. cstring: cstring // Constructor
Cstring ();
Cstring (const cstring & stringsrc );
Cstring (tchar CH, int nrepeat = 1 );
Cstring (maid, int nlength );
Cstring (const unsigned char * psz );
Cstring (lpcwstr lpsz );
Cstring (lpcstr lpsz );
Example:
Cstring S1;
Cstring S2 ("cat ");
Cstring S3 = S2;
Cstring S4 (s2 + "" + S3 );
Cstring s5 ('x'); // S5 = "X"
Cstring S6 ('x', 6); // S6 = "xxxxxx"
Cstring S7 (lpcstr) id_file_new); // S7 = "Create a new document"
Cstring city = "Philadelphia ";
21. cstring: Delete
Int Delete (INT nindex, int ncount = 1 );
Returned value: the length of the string before it is deleted.
Nindex is the first character to be deleted, and ncount is the number of characters to be deleted at a time. According to the results obtained from our experiment: When ncount> is about to delete the maximum length of the string (getcount ()-nindex), an error occurs. When ncount is too large and there are not enough characters to delete it, this function is not executed.
Example:
Cstring str1, str2, str3;
Char;
Str1 = "nihao ";
Str2 = "nihao ";
Int X;
// Int I = (str1 = str2 );
Str1.delete (2, 3 );
If ncount (3)> getcount ()-nindex (5-2), an error is returned.
22. cstring: empty
Void empty ();
Return Value: The empty operation is not returned;
Example:
Cstring S ("ABC ");
S. Empty ();
Assert (S. getlength () = 0 );
23. cstring: Find
Int find (tchar ch) const;
Int find (lpctstr lpszsub) const;
Int find (tchar CH, int nstart) const;
Int find (lpctstr lpszsub, int nstart) const;
Returned value:-1 is returned if the index does not match. The index starts with 0. nstar indicates that the index starts to search with the index value nstart,
It is a string that contains the indexed nstart characters.
Example:
Cstring S ("abcdef ");
Assert (S. Find ('C') = 2 );
Assert (S. Find ("de") = 3 );
Cstring STR ("the stars are aligned ");
Ing n = Str. Find ('E', 5 );
Assert (n = 12)
24. cstring: findoneof
Int findoneof (lpctstr lpszcharset) const;
Returned value:-1 is returned if the index does not match. The index starts with 0.
Note: The first index value in this string that contains characters and starts from scratch in lpszcharset is returned.
Example:
Cstring S ("abcdef ");
Assert (S. findoneof ("XD") = 3); // 'D' is first match.
25. cstring: Format
Void format (lpctstr lpszformat ,...);
Void format (uint nformatid ,...);
Parameter: lpszformat: A format control string
Nformatid string identifier
Example:
Cstring STR;
Str. Format ("% d", 13 );
STR is 13
26. cstring: getat
Tchar getat (INT nindex) const;
Return Value: return the nindex character. You can regard the string as an array. getat is similar to []. Note the nindex range. If not, a debugging error occurs.
27. cstring: getbuffer
Lptstr getbuffer (INT nminbuflength );
Return Value: An lptstr pointer pointing to the buffer space of the object (ending with a null character.
Parameter: nminbuflength
The minimum size of the character buffer, expressed by the number of characters. This value does not include the space of an ending null character.
Note: This member function returns a pointer to the internal character buffer zone of the cstring object. The returned lptstr is not a const, so you can directly modify the cstring content. If you use a pointer returned by getbuffer to change the content of a string, you must call the releasebuffer function before using other cstring member functions.
After calling releasebuffer, the address returned by getbuffer may be invalid, because other cstring operations may cause the cstring buffer to be reallocated. If you do not change the length of the cstring, the buffer will not be reassigned. When the cstring object is destroyed, its buffer memory is automatically released.
Note: If you know the length of a string, you should not add any trailing null characters. However, when you use releasebuffer to release the buffer, you must specify the final string length. If you add an empty character at the end, you should pass-1 to the releasebuffer length parameter, and releasebuffer will execute strlen on the buffer to determine its length.
Example:
// Cstring: getbuffer example
Cstring S ("ABCD ");
# Ifdef _ debug
Afxdump <"cstring s" <S <"/N ";
# Endif
Lptstr P = S. getbuffer (10 );
Strcpy (P, "hello"); // directly access the cstring object.
S. releasebuffer ();
# Ifdef _ debug
Afxdump <"cstring s" <S <"/N ";
# Endif
28. cstring: getlength
Int getlength () const;
Return Value: returns the byte count in the string.
Note: This member function is used to obtain the byte count in the cstring object. This count does not include the ending null characters.
For multi-byte character sets (MBCS), getlength is counted by every eight characters. That is, the start and end bytes in a multi-byte character are counted as two bytes.
Example
The following example shows how to use cstring: getlength.
// Cstring: getlength example
Cstring S ("abcdef ");
Assert (S. getlength () = 6 );
29. cstring: insert
Int insert (INT nindex, tchar ch );
Int insert (INT nindex, lpctstr pstr );
Return Value: return the modified length. The nindex is the inserted index number of a character (or string ).
Example:
Cstring STR ("hockeybest ");
Int n = Str. insert (6, "is ");
Assert (n = Str. getlength ());
Printf ("1: % s/n", (lpctstr) Str );
N = Str. insert (6 ,'');
Assert (n = Str. getlength ());
Printf ("2: % s/n", (lpctstr) Str );
N = Str. insert (555, '1 ');
Assert (n = Str. getlength ());
Printf ("3: % s/n", (lpctstr) Str );
Output
1. hockeyis best
2. Hockey is best
3. Hockey is best!