Cstring: makeuppervoid makeupper (); remarks converts this cstring object to an uppercase string. Convert all lowercase English letters of the original object to uppercase letters. (Only lowercase English letters are converted to uppercase letters. Other characters are not changed, such as uppercase letters, numbers, and Chinese characters.) Example instance the following example demonstrates the use of cstring :: makeupper. // example for cstring: makeuppercstring S ("ABC"); S. makeupper (); Assert (S = "ABC"); receivcstring: makelower void makelower (); remarks converts this cstring object To a lowercase string. Convert all uppercase letters of the original object to lowercase letters. (Only converts uppercase English letters to lowercase letters without changing other characters, such as lowercase letters, numbers, and Chinese characters) Example instance the following example demonstrates the use of cstring :: makelower. // example for cstring: makelowercstring S ("ABC"); S. makelower (); Assert (S = "ABC"); datagcstring: makereversevoid makereverse (); remarks reverses the 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, tchar chnew); int Replace (lpctstr lpszold, lpctstr lpsznew); Return Value Returns the number of replaced instances of the character. Zero if the string isn't changed. This function returns the number of replaced characters. If the original object does not change, 0 is returned. Parameters parameter choldthe character to be replaced by chnew. The character to be replaced by chnew. Chnewthe character replacing chold. Used to replace the chold character. Lpszolda pointer to a string containing the character to be replaced by lpsznew. lpszold is a pointer to a string, and its characters will be replaced by lpsznew. Lpsznewa pointer to a string containing the character replacing lpszold. lpsznew is a pointer to a string. It contains characters used to replace lpszold. Remarks remarks call this member function to replace a character with another. the first prototype of the function replaces instances of chold with chnew In-Place in the string. the second prototype of the function replaces instances of the substring lpszold with Instances
Of the string lpsznew. This function uses another character to replace the original character. The first form replaces chold with chnew in place. In the second form, lpszold is used to replace the sub-chain lpszold of the original object. The string may grow or shrink as a result of the replacement; that is, lpsznew and lpszold do not have to be equal in length. both versions perform case-sensitive matches. the replaced string may be longer or shorter, that is, the length of lpsznew and lpszold must not be equal. Both formats must be case sensitive. Example instance // first example, with old and new equal in length. // In the first example, cstring strzap ("c --"); int n = strzap. replace ('-', '+'); Assert (n = 2); Assert (strzap = "C ++"); // second example, old and new are of different lengths. // In the second example, cstring strbang ("everybody likes ice hockey"); n = strbang. replace ("hockey", "golf"); Assert (n = 1); n = strbang. replace ("likes", "plays"); Assert (n = 1); n = strban G. replace ("ice", null); Assert (n = 1); Assert (strbang = "Everybody plays golf"); (there are two spaces between plays and golf, if null is changed to "", it should be 3 spaces. // note that you now have an extra space in your // sentence. to remove the extra space, include it // In the string to be replaced, I. E ., "Ice ". // note the extra spaces in the sentence. To remove it, the replaced string should be "ice ". Optional cstring: removeint cstring: Remove (tchar ch); return value return the Count of characters removed from the string. zero if the string isn' t changed. returns the number of characters purged from the original object. If the original object does not change, 0 is returned. Parameters parameter chthe character to be removed from a string. The characters to be purged. Remarks remarks call this member function to remove instances of Ch from the string. comparisons for the character are case-sensitive. This function is used to clear the character CH in the original object. Case Insensitive. Example instance // remove the lower-case letter 'T' from a sentence: // clear lower case tcstring STR ("this is a test. "); int n = Str. remove ('T'); Assert (n = 2); Assert (STR = "This Is A es. "); --------------------------------------------------------------------------------------------------------------------------- cstring: insertint insert (INT nindex, tchar ch) Throw (cmemoryexception); int insert (INT nindex, lpctstr Pstr) Throw (cmemoryexception); Return Value Returns the length of the changed string. Parameters parameter nindexthe index of the character before which the insertion will take place. used to determine the Insert Location. Chthe character to be inserted. characters to be inserted. Pstra pointer to the substring to be inserted. The sub-chain pointer to be inserted. Remarks remarks call this member function to insert a single character or a substring at the given index within the string. the nindex parameter identifies the first character that will be moved to make room for the character or substring. if nindex is zero, the insertion
Will occur before the entire string. if nindex is higher than the length of the string, the function will concatenate the present string and the new material provided by either ch or pstr. this function is used to insert a character or sub-chain at a specified position in the original object. The nindex parameter indicates the first character to be moved to the characters or sub-links to be inserted. If nindex is 0, it is inserted at the beginning of the original object. If nindex is longer than the length of the original object, the function connects ch or pstr to the end of the original function. Example instance // The following example demonstrates the use of cstring: insert. 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 ,'! '); Assert (n = Str. getlength (); printf ("3: % s \ n", (lpctstr) Str); // This code generates these lines of output: // The above code generates the following output: 1: hockeyis best2: hockey is best3: hockey is best! --------------------------------------------------------------------------------------------------------------------------- Cstring: deleteint Delete (INT nindex, int ncount = 1) Throw (cmemoryexception); Return Value Returns the length of the changed string. Parameters parameter nindexthe index of the first character to delete. indicates the first character location to be deleted. Ncountthe number of characters to be removed. The number of characters to be deleted. Remarks remarks call this member function to delete a character or characters from a string starting with the character at nindex. if ncount is longer than the string, the remainder of the string will be removed. this function is used to delete the ncount characters starting from the nindex + 1 character in the original object. If ncount is greater than the number of characters in a string (it should start with nindex + 1 character), all characters starting with nindex + 1 will be deleted. Example instance // The following example demonstrates the use of cstring: delete. str2 = "hockey is best! "; Printf (" before: % s \ n ", (lpctstr) str2); int n = str2.delete (6, 3); printf (" after: % s \ n ", (lpctstr) str2); Assert (n = str2.getlength (); // This code generates this line of output: Before: hockey is best! After: hockey best! --------------------------------------------------------------------------------------------------------------------------- Cstring: formatvoid format (lpctstr lpszformat,...); void format (uint nformatid,...); Parameters parameter lpszformata format-control string. Format control string. Nformatidthe string resource identifier that contains the format-control string. Contains the string resource tag of the format control string. Remarks remarks call this member function to write formatted data to a cstring in the same way that sprintf formats data into a C-style character array. this function formats and stores a series of characters and values in the cstring. each Optional argument (if any) is converted
And output according to the corresponding format specification in lpszformat or from the string resource identified by nformatid. this function is used to format data into a cstring object. It is the same as using the sprintf function to format data into a C-language character array. This function formats and stores a series of characters and values in a cstring object. A variable (if any) is converted and output according to the format specified by lpszformat or string resource tag nformatid. The call will fail if the string object itself is offered as a parameter to format. for example, the following code: If the cstring object itself is provided to the format as a parameter, the function fails to be called. For example, the following code: cstring STR = "some data"; Str. format ("% S % d", STR, 123); // attention: STR is also used in the parameter list. // Note: STR is also used as the parameter will cause unpredictable results. this will lead to unpredictable results. When you pass a character string as an optional argument, you must cast it explicitly as lpctstr. the format has the same form and function as the format argument for the printf function. (for a description of the format and arguments, see printf in the run-time
Library Reference.) A null character is appended to the end of the characters written. When the string is passed as a parameter, it must be explicitly declared like the lpctstr. The format and function are the same as those of the printf parameter (for details about the format and parameters, see the sprintf function in the run-time library reference ). No character is added at the end of the written character. For more information, see sprintf in the run-time library reference. For more information, see the sprintf function in the run-time library reference. Example instance cstring STR; Str. format (_ T ("floating point: %. 2f \ n "), 12345.12345); _ tprintf (" % s ", (lpctstr) Str); Str. format (_ T ("left-justified INTEGER: %. 6D \ n "), 35); _ tprintf (" % s ", (lpctstr) Str); Str. format (ids_score, 5, 3); _ tprintf ("% s", (lpctstr) Str ); output if the application has a string resource with the identifier ids_score that contains the string "penguins: % d \ nflyers: % d \ n", the above Code fragm Ent produces this output: if you use the string resource identifier ids_score that contains the string "penguins: % d \ nflyers: % d \ n", the above Code generates the following output: floating point: 12345.12left-justified INTEGER: 000035 penguins: 5 flyers: 3 cstring: formatvvoid formatv (lpctstr lpszformat, va_list Arglist); Parameters parameter lpszformata format-control string. format control string. Arglista list of arguments to be passed. A column of parameters passed. Remarks remarks call this member function to write a formatted string and a variable list of arguments to a cstring object in the same way that vsprintf formats data into a C-style character array. this function formats and stores a series of characters and values in the cstring.
The string and arguments are converted and output according to the corresponding format specification in lpszformat. This function returns a cstring object (?) with a certain format and a parameter table (?), Just like the vsprintf function formatting data into a C-style character array. This function is used to format and store a column of characters and values in cstring. Strings and parameters are formatted and output in the specified format. The call will fail if the string object itself is offered as a parameter to formatv. for example, the following code: If the cstring object itself is provided to formatv as a parameter, the function fails to be called. For example, the following code: cstring STR = "some data"; Str. formatv ("% S % d", STR, 123); // attention: STR is also used in the parameter list. // Note: STR is also used as the parameter will cause unpredictable results. this will lead to unpredictable results. For more information, see vsprintf in the run-time library reference. For more information, see the vsprintf function in the run-time library reference. Example instance // using cstring: formatv (), you can write functions like the following: void writelogentry (cstdiofile & reffile, lpctstr pstrformat ,...) {ctime timewrite; timewrite = ctime: getcurrenttime (); // write the time out cstring STR = timewrite. format ("% d % B % Y % H: % m: % s-"); reffile. write (STR, str. getlength (); // format and write the data we were given va_list ARGs; va_start (ARGs, pstrformat); s TR. formatv (pstrformat, argS); reffile. write (STR, str. getlength (); // put a newline reffile. write ("\ n", 1); return;} You can call the above function with any number of parameters, for example: writelogentry (filelog, "program started "); writelogentry (filelog, "processed % d bytes", 91341); writelogentry (filelog, "% d error (s) found in % d line (s)", 10,135 1 ); writelogentry (filelog, "program completed "); Which wocould add output to your filelog file similar to the following: 17 Apr 97 12:34:53-program started 17 Apr 97 12:34:59-processed 91341 bytes 17 Apr 97 12:35:22-10 error (s) found in 1351 line (s) 17 Apr 97 12:35:23-program completed comment cstring: trimleftvoid trimleft (); Void cstring: trimleft (tchar chtarget); void cstring: trimleft (lpctstr lpsztargets); Parameters parameter chtargetthe target characters to be trimmed. characters to be cleared. Lpsztargetsa pointer to a string containing the target characters to be trimmed. String pointers containing characters to be purged. Remarks remarks call the version of this member function with no parameters to trim leading whitespace characters from the string. when used with no parameters, trimleft removes newline, space, and tab characters. this function has no parameter format to clear the whitespace before the original object (Baidu once, whitespace represents spaces, tabs, carriage return and other special characters, the following description exactly proves its meaning ). Trim line breaks, spaces, and tabs for trimleft without parameters. Use the versions of this function that accept parameters to remove a participant character or a participant group of characters from the beginning of a string. this function contains parameters to clear the specified character or character set before the original object. For more information, see strings topics in Visual C ++ programmer's guide for more instructions, see more in-depth programming topics (VC ++ programmer's guide ?) Strings topics in. Example instance in this example, the string "\ t *** hockey is best! "Becomes" hockey is best! ": In the following example, the string" \ t *** hockey is best! "Changed to" hockey is best! ": Cstring strbefore; cstring strafter; strbefore = _ T (" \ t *** hockey is best! "); Strafter = strbefore; strafter. trimleft (T _ ("\ t *"); _ tprintf (_ T ("before: \" % s \ "\ n"), (lpctstr) strbefore ); _ tprintf (_ T ("after: \" % s \ "\ n"), (lpctstr) strafter); msdn is not clear here, supplement by yourself (not necessarily true after testing): the form without parameters has been clearly stated and does not need to be supplemented; there are two forms of parameters, the previous one can be seen as a special case of the latter. The string pointer lpsztargets is used as a parameter to identify the first character not in lpsztargets from the original object, use this character and its subsequent parts to update the original object. If the first character of the original object does not appear in lpsztargets, the original object remains unchanged. If all the characters of the original object appear in lpsztargets, the original object is empty. This form is similar to cstring: spanincluding. It is used to find the first character that does not appear in the parameter from the original object, except that the former is used to update the original object, while the latter is used to return the previous part. Optional cstring: trimrightvoid trimright (); void cstring: trimright (tchar chtarget); void cstring: trimright (lpctstr lpsztargets); parameterschtargetthe target characters to be trimmed. characters to be purged. Lpsztargetsa pointer to a string containing the target characters to be trimmed. String pointers containing characters to be purged. Remarks remarks call the version of this member function with no parameters to trim trailing whitespace characters from the string. when used with no parameters, trimright removes trailing newline, space, and tab characters from the string. this function has no parameters to clear the whitespace behind the original object. Trim line breaks, spaces, and tabs without parameters. Use the versions of this function that accept parameters to remove a participant character or a participant group of characters from the end of a string. this function contains parameters to clear the specified character or character set after the original object. In fact, it is to start from the end of the original object and find the first character that does not appear in the string that is not pointed to by lpsztargets, and use the character and the previous part to update the original object. After the update, the original object may be empty or unchanged. Example instance cstring strbefore; cstring strafter; strbefore = "hockey is best !!!! "; Strafter = strbefore; Str. trimright ('! '); Printf ("before: \" % s \ "\ n", (lpctstr) strbefore); printf ("after: \ "% s \" \ n ", (lpctstr) strafter); strbefore =" hockey is best ?!?!?!?! "; Strafter = strbefore; Str. trimright ("?! "); Printf (" before: \ "% s \" \ n ", (lpctstr) strbefore); printf (" after: \ "% s \" \ n ", (lpctstr) strafter); in the first example above, the string reading," hockey is best !!!! "Becomes" hockey is best ". In the first example above, the original object is named" hockey is best !!!! "Changed to" hockey is best ". In the second example abve, the string reading, "hockey is best ?!?!?!?! "Becomes" hockey is best ". In the second example above, the original object is named" hockey is best ?!?!?!?! "Changed to" hockey is best ". For more information, see strings topics in Visual C ++ programmer's guide for more instructions, see strings topics in more in-depth programming topics. Export cstring: formatmessagevoid formatmessage (lpctstr lpszformat ,...); void formatmessage (uint nformatid ,...); parameters parameter lpszformatpoints to the format-control string. it will be scanned for inserts and formatted accordingly. the format string is similar to run-time function P Rintf-style format strings, Except t it allows for the parameters to be inserted in an arbitrary order. The format controls the string pointer. The function is to determine the characters to be inserted and their formats. Apart from allowing the parameters to be inserted in any order, the formats are the same as those of printf. Nformatidthe string resource identifier that contains the unformatted message text. String Resource Identifier (?) that contains the unformatted message body (?). Remarks remarks call this member function to format a message string. the function requires a message definition as input. the message definition is determined by lpszformat or from the string resource identified by nformatid. the function copies the formatted Message Text
To the cstring, processing any embedded insert sequences if requested. This function formats the message string, uses the message identified by lpszformat or nformatid as the input, and then copies the message body to the cstring. If necessary, this function processes the inserted items in order. Each insert must have a corresponding parameter following the lpszformat or nformatid parameter. within the message text, several escape sequences are supported for dynamically formatting the message. for a description of these escape sequences and their meanings,
See the windows: formatmessage function in the Win32 SDK programmer's reference. After lpszformat or nformatid, each insert Item must have corresponding parameters. In the message body, dynamic formatting supports some escape sequences ?). Example instance cstring STR; int nasked = 5; int nagree = 4; Str. formatmessage (_ T ("% 1! D! Of % 2! D! Developers agree: hockey is % 3%! "), Nagree, nasked, _ T (" best "); Assert (STR = _ T (" 4 of 5 developers agree: hockey is best! "); Then "));---------------------------------------------------------------------------------------------------------------------------
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.