1. cstring header files
# Include
2. cstring output
Cstring temp = "Hello! ";
Cout
3. cstring usage
Cstring: CompareInt compare (lpctstr lpsz) const;Returns 0 if the return value is the same as the string.If the value is less than lpsz,-1 is returned.If the value is grea
(n = 2 );Assert (STR = "This is a es .");10. cstring: replaceInt Replace (tchar chold, tchar chnew );Int Replace (maid, maid );Return Value: the number of characters to be replaced. If the string is not changed, zero is returned.Parameter: The character chold to be replaced by chnew.Chnew is used to replace the chold
. getlength () = 3); // String Length = 3S. releasebuffer (); // Release excess memory. P is invalid now.Assert (S. getlength () = 3); // The length is still 3
Cstring: RemoveInt cstring: Remove (tchar ch );Return ValueReturns the number of characters removed from the string. If the string is not changed, zero is returned.ParametersChThe character to be removed from a string.DescriptionThis member function
(tchar ch );Return ValueReturns the number of characters removed from the string. If the string is not changed, zero is returned.ParametersChThe character to be removed from a string.DescriptionThis member function is used to remove the CH instance from the string. This character is case sensitive..Example// Remove the lower-case Letter 'c' from a sentence ':Cstring STR ("This is a test .");Int n = Str. Remove ('T ');Assert (n = 2 );Assert (STR = "Th
. After the releasebuffer or other cstring operations are called, the address returned by getbuffer is invalid. example the following example shows how to use cstring: releasebuffer. // cstring: releasebuffer example cstring s; S = "ABC"; lptstr P = S. getbuffer (1024); strcpy (P, "ABC"); // directly use this b
(tchar ch );Return ValueReturns the number of characters removed from the string. If the string is not changed, zero is returned.ParametersChThe character to be removed from a string.DescriptionThis member function is used to remove the CH instance from the string. This character is case sensitive..Example// Remove the lower-case Letter 'c' from a sentence ':Cstring STR ("This is a test .");Int n = Str. Remove ('T ');Assert (n = 2 );Assert (STR = "Th
cstring is based on the tchar data type. if the symbol _ Unicode is defined for your program, tchar is defined as type wchar_t , a 16-bit character type; otherwise, it is defined as char , the normal 8-bit character type. under Unicode, then, cstring objects are composed of 16-bit characters. without Unicode, They are composed of 8-bit char type.
When not using_ Unicode,CstringIs enabled
find the specified value (case sensitive) strcmpStrncmpStrcoll_ Strncoll operator Operator>Operator Operator> =Operator =Operator! = Collate
Compare searches for the specified value (Case Insensitive) _ stricmp_ Strnicmp_ Stricoll_ Strnicoll collatenocase
ComparenocasNote: If the return value is
C) replace
Function char * string cstring to find the specified value _ strset_ StrnsetReplaceReplace_copyRepla
if the string does not change.ParametersChThe character to remove from a string.DescriptionThis member function is used to remove the ch instance from the string. Comparisons with this character are case-sensitiveOfExampleRemove the lowercase letter ' C ' from a sentence:CString Str ("This is a test.");int n = str. Remove (' t ');ASSERT (n = = 2);ASSERT (str = = "This is a es. ” );Cstring::replaceint Replace
can be compared with char * and compared with the value rather than the address;
Cout
Cout
Cout
Cout
(4) common algorithms
A) Search
Char * string cstringFind the specified strchrStrstrStrrstrStrspfind findThe first matched value fild_first_of findoneof starts from the end to find reservefind. The specified matching method is find_if.
Note: In find_if, values in the range are substituted into the matching function one by one until true is returned.
B) Comparison
Function char * string
order of Characters in this cstring object. Reverse all characters of the original object. Example instance the following example demonstrates the use of cstring: makereverse. // example for cstring: makereversecstring S ("ABC"); S. makereverse (); Assert (S = "CBA"); effeccstring: replaceint Replace (tchar chold, tch
Findoneof
Start searching later
Reservefind
Matching Method
Find_if
Note: In find_if, values in the range are substituted into the matching function one by one until true is returned.
B) Comparison
Function
Char *
String
Cstring
Search for a specified value (case sensitive)
StrcmpStrncmpStrcoll_ Strncoll
Operator Operator>Operator Operator> =Operator =Operator! =
Col
How to split data of the CString type in MFC and that of the cstring type in mfc
[It is easy to learn, but it is inevitable that there are some mistakes. If there are any errors, please advise]
There is a library function Tokenize () in MFC ();
Function prototype: CStringT Tokenize (PCXSTR pszTokens, int iStart) const;
This function can be used to separate CString
CString is located in the header file afx.h.
member functions for CStringthe CString constructor CString ();Example: CString csstr; CString (const cstring STRINGSRC);Example: CStrin
Find_if
Note: In find_if, values in the range are substituted into the matching function one by one until true is returned.
B) Comparison
Function
Char *
String
Cstring
Search for a specified value (case sensitive)
StrcmpStrncmpStrcoll_ Strncoll
Operator Operator>Operator Operator> =Operator =Operator! =
CollateCompare
Search for the specified value (Case Insensitive)
_ Stricmp_ Strni
Find
The first matched Value
Fild_first_of
Findoneof
Start searching later
Reservefind
Matching Method
Find_if
Note: In find_if, values in the range are substituted into the matching function one by one until true is returned.
B) Comparison
Function
Char *
String
Cstring
Search for a specified value (case sensitive)
S
Find_if
Note: In find_if, the values in the range are put into the matching function until Trueb) Comparison
Role
char*
String
CString
Find specified value (case sensitive)
strcmpstrncmpStrcoll_strncoll
operatorOperator>operatoroperator>=operator==operator!=
CollateCompare
Find specified value (case insensitive)
_stricmp_strnicmp_stricoll_strn
\ coolstuff ")Bool result = dosomethingcool (File );It runs correctly. Because the dosomethingcool function has already stated that a parameter of the lpctstr type is required, therefore, the lpctstr is applied to this parameter, and the return string address is in MFC.
What if you want to format a string?
Cstring graycat ("graycat ");Cstring S;S. Format ("mew! I love % s ", graycat );Note that the value i
find the specified character ch, returns its position, and returns 1 if it is not found. It is important to note that the index of the position is to be counted from the beginning, although it is looked up from behind.C + + codecstring str = _t ( " Jizhuomi " ); int nIndex1 = str. Find (_t ( " zh ")"; // int nIndex2 = str. Findoneof (_t ( " mui ")"; // int nIndex3 = str. Reversefind (_t ( ' i ")"; // The value of NINDEX3 is 7 7. substitution and deletion of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.