MSDN中关于CString类成员函数的说明_第1页
MSDN中关于CString类成员函数的说明_第2页
MSDN中关于CString类成员函数的说明_第3页
MSDN中关于CString类成员函数的说明_第4页
MSDN中关于CString类成员函数的说明_第5页
已阅读5页,还剩52页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、msdn中关于cstring类成员函数的说明msdn中关于cstring类成员函数的说明msdn中关于cstring类成员函数的说明2006-09-26 21:31other conversions-cstring:makeuppervoid makeupper( );remarks备注converts this cstring object to an uppercase string.将原对象的所有小写英文字母转换为大写。(只是将小写的英文字母转换为大写,对于其它的字符不做变化,例如:大写字符,数字,汉字)example实例the following example demonstrate

2、s the use of cstring:makeupper./ example for cstring:makeuppercstring s( abc );s.makeupper();assert( s = abc );-cstring:makelowervoid makelower( );remarks备注converts this cstring object to a lowercase string.将原对象的所有大写英文字母转换为小写。(只是将大写的英文字母转换为小写,对于其它的字符不做变化,例如:小写字符,数字,汉字)example实例the following example

3、demonstrates the use of cstring:makelower./ example for cstring:makelowercstring s( abc );s.makelower();assert( s = abc );-cstring:makereverse void makereverse( );remarks备注reverses the order of the characters in this cstring object.将原对象的所有字符颠倒顺序。example实例the following example demonstrates the use of

4、 cstring:makereverse./ example for cstring:makereversecstring 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 c

5、hanged.该函数返回替换的字符数量。如果原对象没有改变则返回0。parameters参数choldthe 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

6、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 in

7、stances 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-sensi

8、tive matches.替换后的字符串有可能变长,也有可能缩短,也就是说,lpsznew和lpszold的长度不必相等。两个形态都要区别大小写。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./第二个例子,长度不相等的情况cstr

9、ing strbang(everybody likes ice hockey);n = strbang.replace(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 spac

10、e in your/ sentence. to remove the extra space, include 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.返回原对象中被清除的字符个数。如果原对象没有改

11、变,则返回0。parameters参数chthe 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实例/remove the lower-case letter t from a sentence:/清除句子中的小写tcstring str

12、(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返回值the length of the changed string. 返回改变后的字符串长度。parameters参数nindex

13、the index of the character before which the insertion will 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 nin

14、dex 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

15、provided by either ch or pstr.该函数用来在原对象中的指定位置插入一个字符或子链。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.getl

16、ength(); printf(1: %sn, (lpctstr) str); n = str.insert(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

17、 is best!-cstring:deleteint delete( int nindex, int ncount = 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 thi

18、s 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个字符开始的所有字符。examp

19、le实例/the following example demonstrates the use of cstring: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 bes

20、t!-cstring:formatvoid format( lpctstr lpszformat, . );void 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 t

21、o 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 t

22、he 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:如果

23、cstring对象本身被当作参数提供给format,那么函数会调用失败。例如下面的代码: cstring str = 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 lpctst

24、r. 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一样明确地声明它。其格式和功能与print

25、f的形参一样(关于格式和参数的说明,参阅run-time library reference中的sprintf函数)。写入字符的末端没有字符被添加。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.f

26、ormat(_t(left-justified integer: %.6dn), 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: %dnflyers : %dn, the above code fragment produces this o

27、utput:如果使用包含字符串penguins: %dnflyers : %dn的字符串资源标识符ids_score,则上面的代码将产生如下输出:floating point: 12345.12left-justified integer: 000035penguins: 5flyers : 3 -cstring:formatvvoid formatv( lpctstr lpszformat, va_list arglist );parameters参数lpszformata format-control string.格式控制字符串。arglista list of arguments to

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

29、ring 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 forma

30、tv. for example, the following code:如果cstring对象本身被当作参数提供给formatv,那么函数会调用失败。例如下面的代码: cstring str = some data;str.formatv(%s%d, str, 123); / attention: str is also used in the parameter list./注意:str也被用作参数will cause unpredictable results.将导致不可预知的结果。for more information, see vsprintf in the run-time lib

31、rary reference.更多说明参阅run-time library reference(运行库参考手册)中的vsprintf函数。example实例/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 = ti

32、mewrite.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); str.formatv(pstrformat, args); reffile.write(str, str.getlength(); / put a newline reffile.write(n, 1); return;you can call the above function

33、 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, 1351); writelogentry(filelog, program completed);which would add output to your filelog file similar to

34、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-cstring:trimleftvoid trimleft( );void cstring:trimleft( tchar chtarget );void cstring:trimleft( lpctstr lpsztarg

35、ets );parameters参数chtargetthe target characters to be trimmed.需要被清除的字符。lpsztargetsa 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

36、 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 charac

37、ters from the beginning of a string.含有参数的该函数用来清除原对象前面的指定的字符或字符集。for more information, see strings topics in visual c+ programmers guide更多说明参阅更加深入的编程话题(vc+程序员指南?)中的strings topics。 example实例in this example, the string tt *hockey is best! becomes hockey is best!:下面的例子,字符串 tt *hockey is best!变成了 hockey

38、is best!:cstring strbefore;cstring strafter;strbefore = _t(tt *hockey is best!);strafter = strbefore;strafter.trimleft(t_(t *);_tprintf(_t(before: %sn), (lpctstr) strbefore);_tprintf(_t(after : %sn), (lpctstr) strafter);msdn这里完全没说清楚,自己补充(通过测试自己总结的,不一定对): 没有参数的形式已经说清楚了,无须补充;有参数的两种形式,前一种可以看作后一种的特例; 接受

39、字符串指针lpsztargets作为参数的形式,从原对象中找出第一个没有在lpsztargets中出现的字符,将此字符及其之后的部分用来更新原对象。若原对象的第一个字符没有在lpsztargets中出现,则原对象不变;若原对象的所有字符都在lpsztargets中出现,则原对象为空。 该形式和cstring:spanincluding类似,都是从原对象中找出第一个没有在参数中出现的字符,只是前者用后面部分更新原对象,而后者是返回前面部分。-cstring:trimrightvoid trimright( );void cstring:trimright( tchar chtarget );vo

40、id cstring:trimright( lpctstr lpsztargets );parameterschtargetthe target characters to be trimmed.需要被清除的字符。lpsztargetsa 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

41、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

42、group of characters from the end of a string.含有参数的该函数用来清除原对象后面的指定的字符或字符集。实际上就是从原对象最后面开始,向前找出第一个没有在lpsztargets所指向的字符串中出现的字符,将该字符及其前面的部分用来更新原对象。更新后原对象有可能为空,也有可能不变。example实例cstring strbefore;cstring strafter; strbefore = hockey is best!; strafter = strbefore; str.trimright(!); printf(before: %sn, (lpct

43、str) strbefore); printf(after : %snn, (lpctstr) strafter); strbefore = hockey is best?!?!?!?!; strafter = strbefore; str.trimright(?!); printf(before: %sn, (lpctstr) strbefore); printf(after : %snn, (lpctstr) strafter);in the first example above, the string reading, hockey is best! becomes hockey is

44、 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+ programmers guide更多说明参阅更加深入的编程话题中的strings

45、 topics。-cstring:formatmessagevoid formatmessage( lpctstr lpszformat, . );void formatmessage( uint nformatid, . );parameters参数lpszformatpoints 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

46、 strings, except it allows for the parameters to be inserted in an arbitrary order.格式控制字符串指针。其作用是确定插入的字符及其格式,除了允许参数可以按照任意的顺序插入外,和(运行函数)printf的格式相同。nformatidthe string resource identifier that contains the unformatted message text.包含无格式的消息正文的字符串资源标识符(?)。remarks备注call this member function to format a

47、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.该函数格式化消息串,

48、将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

49、sequences and their meanings, see the windows :formatmessage function in the win32 sdk programmers reference.在 lpszformat或nformatid后面,每个插入项必须有相应的参数。在消息正文中,动态格式化支持一些escape sequences(换码顺序?)。example实例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!);-cstring:compareint compare( lpctstr lpsz ) const;返回值 字符串一样 返回0 小于lpsz 返回-1 大于lpsz 返回1 区分大小字符 cstring s1( abc );cstring s2( abd );assert( s1.compare( s2 ) = -1 );assert( s1.compare( abe ) = -1 );cst

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论