Other Conversions --------------------------------------------------------------------------------------------------------------------------- CString::MakeUppervoid MakeUpper( ); Remarks 备注 Converts this CString object to an uppercase string. 将原对象的所有小写英文字母转换为大写。 (只是将小写的英文字母转换为大写,对于其它的字符不做变化,例如:大写字符,数字,汉字) Example 实例 The following example demonstrates the use of CString::MakeUpper.
--------------------------------------------------------------------------------------------------------------------------- CString::MakeLowervoid MakeLower( ); Remarks 备注 Converts this CString object to a lowercase string. 将原对象的所有大写英文字母转换为小写。 (只是将大写的英文字母转换为小写,对于其它的字符不做变化,例如:小写字符,数字,汉字) Example 实例 The following example demonstrates the use of CString::MakeLower.
--------------------------------------------------------------------------------------------------------------------------- CString::MakeReversevoid MakeReverse( ); Remarks 备注 Reverses the order of the characters in this CString object. 将原对象的所有字符颠倒顺序。 Example 实例 The following example demonstrates the use of CString::MakeReverse.
--------------------------------------------------------------------------------------------------------------------------- CString::Replaceint Replace( TCHAR chOld, TCHAR chNew ); int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew ); Return Value 返回值 The number of replaced instances of the character. Zero if the string isn't changed. 该函数返回替换的字符数量。如果原对象没有改变则返回0。 Parameters 参数 chOld The character to be replaced by chNew. 将要被chNew所代替的字符。 chNew The character replacing chOld. 用来替换chOld的字符。 lpszOld A pointer to a string containing the character to be replaced by lpszNew. lpszOld是一个指向字符串的指针,它所包含的字符将被lpszNew所代替。 lpszNew A pointer to a string containing the character replacing lpszOld. lpszNew是一个指向字符串的指针,它所包含的字符用来替换lpszOld。 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. 该函数用另外的字符来代替原来的字符。第一种形态,用chNew就地取代chOld。第二种形态,用lpszNew来取代原对象的子链lpszOld。 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. 替换后的字符串有可能变长,也有可能缩短,也就是说,lpszNew和lpszOld的长度不必相等。两个形态都要区别大小写。 Example 实例
--------------------------------------------------------------------------------------------------------------------------- CString::Removeint CString::Remove( TCHAR ch ); Return Value 返回值 The count of characters removed from the string. Zero if the string isn't changed. 返回原对象中被清除的字符个数。如果原对象没有改变,则返回0。 Parameters 参数 ch The character to be removed from a string. 需要清除的字符。 Remarks 备注 Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive. 该函数用来清除原对象中的字符ch。大小写不等效。 Example 实例
--------------------------------------------------------------------------------------------------------------------------- CString::Insertint Insert( int nIndex, TCHAR ch ) int Insert( int nIndex, LPCTSTR pstr ) Return Value 返回值 The length of the changed string. 返回改变后的字符串长度。 Parameters 参数 nIndex The index of the character before which the insertion will take place. 用来确定插入的位置。 ch The character to be inserted. 需要插入的字符。 pstr A pointer to the substring to be inserted. 需要插入的子链的指针。 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. 该函数用来在原对象中的指定位置插入一个字符或子链。nIndex参数表示第一个为了给插入的字符或子链让位而被移动的字符。如果nIndex 为0,则在原对象的最前面插入。如果nIndex 大于了原对象的长度,该函数就将ch或者pstr连接到原函数的最后面。 Example 实例
--------------------------------------------------------------------------------------------------------------------------- CString::Deleteint Delete( int nIndex, int nCount = 1 ) Return Value 返回值 The length of the changed string. 返回改变后的字符串长度。 Parameters 参数 nIndex The index of the first character to delete. 表示第一个需要被删除的字符位置。 nCount The number of characters to be removed. 需要删除的字符个数。 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. 该函数用来删除原对象中从第nIndex+1个字符开始的nCount 个字符。如果nCount比字符串(应该是从第nIndex+1个字符开始的子链)的字符个数大,那么删除的就是从nIndex+1个字符开始的所有字符。 Example 实例
--------------------------------------------------------------------------------------------------------------------------- CString::Formatvoid Format( LPCTSTR lpszFormat, ... ); void Format( UINT nFormatID, ... ); Parameters 参数 lpszFormat A format-control string. 格式控制字符串。 nFormatID The string resource identifier that contains the format-control string. 包含格式控制字符串的字符串资源标记。 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. 该函数将数据格式化为CString对象,其用法和使用sprintf函数将数据格式化为C语言风格的字符数组一样。该函数将一连串的字符和数值格式化并存放到CString对象中。某变量(如果有)被转换,并且按照lpszFormat或者字符串资源标记nFormatID规定的格式输出。 The call will fail if the string object itself is offered as a parameter to Format. For example, the following code: 如果CString对象本身被当作参数提供给Format,那么函数会调用失败。例如下面的代码:
will cause 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. 当把字符串当作参数传递的时候,必须象LPCTSTR一样明确地声明它。其格式和功能与printf的形参一样(关于格式和参数的说明,参阅Run-Time Library Reference中的sprintf函数)。写入字符的末端没有字符被添加。 For more information, see sprintf in the Run-Time Library Reference. 更多说明参阅Run-Time Library Reference(运行库参考手册)中的sprintf函数。 Example 实例
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 fragment produces this output: 如果使用包含字符串"Penguins: %d\nFlyers : %d\n"的字符串资源标识符IDS_SCORE,则上面的代码将产生如下输出:
--------------------------------------------------------------------------------------------------------------------------- CString::FormatVvoid FormatV( LPCTSTR lpszFormat, va_list argList ); Parameters 参数 lpszFormat A format-control string. 格式控制字符串。 argList A list of arguments to be passed. 被传递的一列参数。 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. 该函数返回一个具有一定格式和一个参数表的CString对象(?),就象vsprintf函数将数据格式化为C风格的字符数组一样。该函数格式化并储存一列字符和数值在CString中。字符串和参数按指定的格式格式化并输出。 The call will fail if the string object itself is offered as a parameter to FormatV. For example, the following code: 如果CString对象本身被当作参数提供给FormatV,那么函数会调用失败。例如下面的代码:
will cause unpredictable results. 将导致不可预知的结果。 For more information, see vsprintf in the Run-Time Library Reference. 更多说明参阅Run-Time Library Reference(运行库参考手册)中的vsprintf函数。 Example 实例
You can call the above function with any number of parameters, for example:
which would add output to your fileLog file similar to the following:
--------------------------------------------------------------------------------------------------------------------------- CString::TrimLeftvoid TrimLeft( ); void CString::TrimLeft( TCHAR chTarget ); void CString::TrimLeft( LPCTSTR lpszTargets ); Parameters 参数 chTarget The target characters to be trimmed. 需要被清除的字符。 lpszTargets A pointer to a string containing the target characters to be trimmed. 含有需要被清除字符的字符串指针。 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. 该函数没有参数的形式用来清除原对象前面的whitespace(百度了一下,whitespace 表示空格、制表符、回车等特殊字符,后面的说明正好证明了其含义)。不含参数的TrimLeft清除换行,空格,制表符。 Use the versions of this function that accept parameters to remove a particular character or a particular group of characters from the beginning of a string. 含有参数的该函数用来清除原对象前面的指定的字符或字符集。 For more information, see Strings Topics in Visual C++ Programmer's Guide 更多说明参阅更加深入的编程话题(VC++程序员指南?)中的Strings Topics。 Example 实例 In this example, the string "\t\t ****Hockey is best!" becomes "Hockey is best!": 下面的例子,字符串 "\t\t ****Hockey is best!" 变成了 "Hockey is best!":
--------------------------------------------------------------------------------------------------------------------------- CString::TrimRightvoid TrimRight( ); void CString::TrimRight( TCHAR chTarget ); void CString::TrimRight( LPCTSTR lpszTargets ); Parameters chTarget The target characters to be trimmed. 需要被清除的字符。 lpszTargets A pointer to a string containing the target characters to be trimmed. 含有需要被清除字符的字符串指针。 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. 该函数没有参数的形式用来清除原对象后面的whitespace。不含参数的TrimRight清除换行,空格,制表符。 Use the versions of this function that accept parameters to remove a particular character or a particular group of characters from the end of a string. 含有参数的该函数用来清除原对象后面的指定的字符或字符集。 实际上就是从原对象最后面开始,向前找出第一个没有在lpszTargets所指向的字符串中出现的字符,将该字符及其前面的部分用来更新原对象。更新后原对象有可能为空,也有可能不变。 Example 实例
In the first example above, the string reading, "Hockey is Best!!!!" becomes "Hockey is Best". 上面的第一个例子,原对象由"Hockey is Best!!!!" 变成了 "Hockey is Best"。 In the second example above, the string reading, , "Hockey is Best?!?!?!?!" becomes "Hockey is Best". 上面的第二个例子,原对象由"Hockey is Best?!?!?!?!" 变成了 "Hockey is Best"。 For more information, see Strings Topics in Visual C++ Programmer's Guide 更多说明参阅更加深入的编程话题中的Strings Topics。 --------------------------------------------------------------------------------------------------------------------------- CString::FormatMessagevoid FormatMessage( LPCTSTR lpszFormat, ... ); void FormatMessage( UINT nFormatID, ... ); Parameters 参数 lpszFormat Points to the format-control string. It will be scanned for inserts and formatted accordingly. The format string is similar to run-time function printf-style format strings, except it allows for the parameters to be inserted in an arbitrary order. 格式控制字符串指针。其作用是确定插入的字符及其格式,除了允许参数可以按照任意的顺序插入外,和(运行函数)printf的格式相同。 nFormatID The string resource identifier that contains the unformatted message text. 包含无格式的消息正文的字符串资源标识符(?)。 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. 该函数格式化消息串,将lpszFormat 或nFormatID确定的消息作为输入,然后复制消息正文到CString。若需要,该函数按顺序处理插入项。 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. 在 lpszFormat或nFormatID后面,每个插入项必须有相应的参数。在消息正文中,动态格式化支持一些escape sequences(换码顺序?)。 Example 实例
--------------------------------------------------------------------------------------------------------------------------- |
MSDN中关于CString类成员函数的说明
最新推荐文章于 2024-03-04 11:30:27 发布
MSDN中关于CString类成员函数的说明
2006-09-26 21:31