ImageVerifierCode 换一换
格式:DOCX , 页数:31 ,大小:25.71KB ,
资源ID:23393511      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/23393511.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(MFC CString的用法.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

MFC CString的用法.docx

1、MFC CString的用法MFC CString 的一些函数2008-12-11 11:52CString:MakeUppervoid MakeUpper( );Remarks备注Converts this CString object to an uppercase string.将原对象的所有小写英文字母转换为大写。(只是将小写的英文字母转换为大写,对于其它的字符不做变化,例如:大写字符,数字,汉字)Example实例The following example demonstrates the use of CString:MakeUpper./ example for CString:

2、MakeUpperCString s( abc );s.MakeUpper();ASSERT( s = ABC );-CString:MakeLower void MakeLower( );Remarks备注Converts this CString object to a lowercase string.将原对象的所有大写英文字母转换为小写。(只是将大写的英文字母转换为小写,对于其它的字符不做变化,例如:小写字符,数字,汉字)Example实例The following example demonstrates the use of CString:MakeLower./ example

3、for CString:MakeLowerCString s( ABC );s.MakeLower();ASSERT( s = abc );-CString:MakeReversevoid MakeReverse( );Remarks备注Reverses the order of the characters in this CString object.将原对象的所有字符颠倒顺序。Example实例The following example demonstrates the use of CString:MakeReverse./ example for CString:MakeRevers

4、eCString s( abc );s.MakeReverse();ASSERT( s = cba );-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 isnt changed.该函数返回替换的字符数量。如果原对象没有改变则返回0。Parameters参数chOldTh

5、e character to be replaced by chNew.将要被chNew所代替的字符。chNewThe character replacing chOld.用来替换chOld的字符。lpszOldA pointer to a string containing the character to be replaced by lpszNew.lpszOld是一个指向字符串的指针,它所包含的字符将被lpszNew所代替。lpszNewA pointer to a string containing the character replacing lpszOld.lpszNew是一个

6、指向字符串的指针,它所包含的字符用来替换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 th

7、e 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的

8、长度不必相等。两个形态都要区别大小写。Example实例/First example, with old and new equal in length./第一个例子,长度相等的情况CString strZap(C-);int n = strZap.Replace(-, +);ASSERT(n = 2);ASSERT(strZap = C+);/Second example, old and new are of different lengths./第二个例子,长度不相等的情况CString strBang(Everybody likes ice hockey);n = strBang.Re

9、place(hockey, golf);ASSERT(n = 1);n = strBang.Replace(likes, plays);ASSERT(n = 1);n = strBang.Replace(ice, NULL);ASSERT(n = 1);ASSERT(strBang = Everybody plays golf);(这里plays和golf之间是两个空格,如果NULL换成 ,那么就应该是3个空格)/ note that you now have an extra space in your/ sentence. To remove the extra space, includ

10、e it / in the string to be replaced, i.e.,ice ./注意句子中额外的空格。要消除它,那么被替换的字符串应该是ice 。-CString:Removeint CString:Remove( TCHAR ch );Return Value返回值The count of characters removed from the string. Zero if the string isnt changed.返回原对象中被清除的字符个数。如果原对象没有改变,则返回0。Parameters参数chThe character to be removed from

11、a string.需要清除的字符。Remarks备注Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive.该函数用来清除原对象中的字符ch。大小写不等效。Example实例/remove the lower-case letter t from a sentence:/清除句子中的小写tCString str(This is a test.);int n = str.Remove(t);ASSERT(n = 2);

12、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返回值The length of the changed string.返回改变后的字符串长度。Parameters参数nIndexThe index of the character before which the insertion w

13、ill take place.用来确定插入的位置。chThe character to be inserted.需要插入的字符。pstrA 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

14、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.该函数用来在原对象中的指定位置插入一个字符或子链。

15、nIndex参数表示第一个为了给插入的字符或子链让位而被移动的字符。如果nIndex 为0,则在原对象的最前面插入。如果nIndex 大于了原对象的长度,该函数就将ch或者pstr连接到原函数的最后面。Example实例/The following example demonstrates the use of CString:Insert. CString str(HockeyBest); int n = str.Insert(6, is ); ASSERT(n = str.GetLength(); printf(1: %sn, (LPCTSTR) str); n = str.Insert(

16、6, ); ASSERT(n = str.GetLength(); printf(2: %sn, (LPCTSTR) str); n = str.Insert(555, !); ASSERT(n = str.GetLength(); printf(3: %sn, (LPCTSTR) str);/this code generates these lines of output:/以上代码产生如下的输出:1: Hockeyis Best2: Hockey is Best3: Hockey is Best!-CString:Deleteint Delete( int nIndex, int nCo

17、unt = 1 )throw( CMemoryException );Return Value返回值The length of the changed string.返回改变后的字符串长度。Parameters参数nIndexThe index of the first character to delete.表示第一个需要被删除的字符位置。nCountThe number of characters to be removed.需要删除的字符个数。Remarks备注Call this member function to delete a character or characters fr

18、om 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实例/The following example demonstrates the use of CStri

19、ng:Delete. str2 = Hockey is best!; printf(Before: %sn, (LPCTSTR) str2); int n = str2.Delete(6, 3); printf(After: %sn, (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, . );vo

20、id Format( UINT nFormatID, . );Parameters参数lpszFormatA format-control string.格式控制字符串。nFormatIDThe 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 int

21、o 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.该函数将数据格式化为CStr

22、ing对象,其用法和使用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,那么函数会调用失败。例如下面的代码:CString str =

23、 Some Data;str.Format(%s%d, str, 123);/ Attention: str is also used in the parameter list./注意:str也被用作参数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

24、 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函数)

25、。写入字符的末端没有字符被添加。For more information, see sprintf in the Run-Time Library Reference.更多说明参阅Run-Time Library Reference(运行库参考手册)中的sprintf函数。Example实例CString str;str.Format(_T(Floating point: %.2fn), 12345.12345);_tprintf(%s, (LPCTSTR) str);str.Format(_T(Left-justified integer: %.6dn), 35);_tprintf(%s,

26、(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: %dnFlyers : %dn, the above code fragment produces this output:如果使用包含字符串Penguins: %dnFlyers : %dn的字符串资源标识符IDS_SCORE,

27、则上面的代码将产生如下输出:Floating point: 12345.12Left-justified integer: 000035Penguins: 5Flyers : 3CString:FormatVvoid FormatV( LPCTSTR lpszFormat, va_list argList );Parameters参数lpszFormatA format-control string.格式控制字符串。argListA list of arguments to be passed.被传递的一列参数。Remarks备注Call this member function to wri

28、te 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

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1