版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、MSDN中關于CString類成員函數(shù)的說明Other Conversions(已完成)2006-09-26 21:31Other Conversions-CString:MakeUppervoid MakeUpper( );Remarks備注Converts this CString object to an uppercase string.將原對象的所有小寫英文字母轉換為大寫。(只是將小寫的英文字母轉換為大寫,對于其它的字符不做變化,例如:大寫字符,數(shù)字,漢字)Example實例The following example demonstrates the use of CString:M
2、akeUpper./ example for CString:MakeUpperCString s( "abc" );s.MakeUpper();ASSERT( s = "ABC" );-CString:MakeLowervoid MakeLower( );Remarks備注Converts this CString object to a lowercase string.將原對象的所有大寫英文字母轉換為小寫。(只是將大寫的英文字母轉換為小寫,對于其它的字符不做變化,例如:小寫字符,數(shù)字,漢字)Example實例The following exampl
3、e demonstrates the use of CString:MakeLower./ example 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 exampl
4、e demonstrates the use of 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 inst
5、ances of the character. Zero if the string isn't changed.該函數(shù)返回替換的字符數(shù)量。如果原對象沒有改變則返回0。Parameters參數(shù)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是一個指向字
6、符串的指針,它所包含的字符將被lpszNew所代替。 lpszNewA 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
7、string. The second prototype of the function replaces instances of the substring lpszOld with instances of the string lpszNew.該函數(shù)用另外的字符來代替原來的字符。第一種形態(tài),用chNew就地取代chOld。第二種形態(tài),用lpszNew來取代原對象的子鏈lpszOld。 The string may grow or shrink as a result of the replacement; that is, lpszNew and lpszOld do not have
8、 to be equal in length. Both versions perform case-sensitive matches.替換后的字符串有可能變長,也有可能縮短,也就是說,lpszNew和lpszOld的長度不必相等。兩個形態(tài)都要區(qū)別大小寫。 Example實例/First example, with old and new equal in length./第一個例子,長度相等的情況CString strZap("C-");int n = strZap.Replace('-', '+');ASSERT(n = 2);ASSE
9、RT(strZap = "C+");/Second example, old and new are of different lengths./第二個例子,長度不相等的情況CString strBang("Everybody likes ice hockey");n = strBang.Replace("hockey", "golf");ASSERT(n = 1);n = strBang.Replace("likes", "plays");ASSERT(n = 1);n =
10、 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, include it/ in the string to be replaced, i.e.,"ic
11、e "./注意句子中額外的空格。要消除它,那么被替換的字符串應該是"ice "。-CString:Removeint CString:Remove( TCHAR ch );Return Value返回值The count of characters removed from the string. Zero if the string isn't changed. 返回原對象中被清除的字符個數(shù)。如果原對象沒有改變,則返回0。Parameters參數(shù)chThe character to be removed from a string.需要清除的字符。Rem
12、arks備注Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive.該函數(shù)用來清除原對象中的字符ch。大小寫不等效。Example實例/remove the lower-case letter 't' from a sentence:/清除句子中的小寫tCString str("This is a test.");int n = str.Remove('t');AS
13、SERT(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參數(shù)nIndexThe index of the character befo
14、re 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 nIndex parameter identifies the f
15、irst 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.
16、該函數(shù)用來在原對象中的指定位置插入一個字符或子鏈。nIndex參數(shù)表示第一個為了給插入的字符或子鏈讓位而被移動的字符。如果nIndex 為0,則在原對象的最前面插入。如果nIndex 大于了原對象的長度,該函數(shù)就將ch或者pstr連接到原函數(shù)的最后面。 Example實例/The following example demonstrates the use of CString:Insert.CString str("HockeyBest");int n = str.Insert(6, "is ");ASSERT(n = str.GetLength();
17、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:/以上代碼產(chǎn)生如下的輸出:
18、1: Hockeyis Best2: Hockey is Best3: Hockey is Best!-CString:Deleteint Delete( int nIndex, int nCount = 1 )throw( CMemoryException );Return Value返回值The length of the changed string. 返回改變后的字符串長度。Parameters參數(shù)nIndexThe index of the first character to delete. 表示第一個需要被刪除的字符位置。nCountThe number of character
19、s to be removed. 需要刪除的字符個數(shù)。Remarks備注Call this member function to delete a character or characters from a string starting with the character at nIndex. IfnCount is longer than the string, the remainder of the string will be removed.該函數(shù)用來刪除原對象中從第nIndex+1個字符開始的nCount 個字符。如果nCount比字符串(應該是從第nIndex+1個字符開始
20、的子鏈)的字符個數(shù)大,那么刪除的就是從nIndex+1個字符開始的所有字符。Example實例/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 co
21、de generates this line of output:Before: Hockey is best!After: Hockey best!-CString:Formatvoid Format( LPCTSTR lpszFormat, . );void Format( UINT nFormatID, . );Parameters參數(shù)lpszFormatA format-control string.格式控制字符串。nFormatIDThe string resource identifier that contains the format-control string.包含格式控制
22、字符串的字符串資源標記。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 acc
23、ording to the corresponding format specification in lpszFormat or from the stringresource identified by nFormatID.該函數(shù)將數(shù)據(jù)格式化為CString對象,其用法和使用sprintf函數(shù)將數(shù)據(jù)格式化為C語言風格的字符數(shù)組一樣。該函數(shù)將一連串的字符和數(shù)值格式化并存放到CString對象中。某變量(如果有)被轉換,并且按照lpszFormat或者字符串資源標記nFormatID規(guī)定的格式輸出。The call will fail if the string object itself i
24、s offered as a parameter to Format. For example, the following code: 如果CString對象本身被當作參數(shù)提供給Format,那么函數(shù)會調(diào)用失敗。例如下面的代碼:CString str = "Some Data"str.Format("%s%d", str, 123);/ Attention: str is also used in the parameter list./注意:str也被用作參數(shù)will cause unpredictable results.將導致不可預知的結果。Wh
25、en 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
26、 appended to the end of the characters written.當把字符串當作參數(shù)傳遞的時候,必須象LPCTSTR一樣明確地聲明它。其格式和功能與printf的形參一樣(關于格式和參數(shù)的說明,參閱Run-Time Library Reference中的sprintf函數(shù))。寫入字符的末端沒有字符被添加。For more information, see sprintf in the Run-Time Library Reference.更多說明參閱Run-Time Library Reference(運行庫參考手冊)中的sprintf函數(shù)。Example實例CSt
27、ring str;str.Format(_T("Floating point: %.2fn"), 12345.12345);_tprintf("%s", (LPCTSTR) str);str.Format(_T("Left-justified integer: %.6dn"), 35);_tprintf("%s", (LPCTSTR) str);str.Format(IDS_SCORE, 5, 3);_tprintf("%s", (LPCTSTR) str);Output輸出If the app
28、lication has a string resource with the identifier IDS_SCORE "Penguins: %dnFlyers : %dn", the above code fragment produces this output: that contains the string如果使用包含字符串"Penguins: %dnFlyers : %dn"的字符串資源標識符IDS_SCORE,則上面的代碼將產(chǎn)生如下輸出: Floating point: 12345.12Left-justified integer: 00
29、0035Penguins: 5Flyers : 3-CString:FormatVvoid FormatV( LPCTSTR lpszFormat, va_list argList );Parameters參數(shù)lpszFormatA format-control string.格式控制字符串。argListA list of arguments to be passed.被傳遞的一列參數(shù)。Remarks備注Call this member function to write a formatted string and a variable list of arguments to a CSt
30、ring 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.該函數(shù)返回一個具有一定格式和
31、一個參數(shù)表的CString對象(?),就象vsprintf函數(shù)將數(shù)據(jù)格式化為C風格的字符數(shù)組一樣。該函數(shù)格式化并儲存一列字符和數(shù)值在CString中。字符串和參數(shù)按指定的格式格式化并輸出。The call will fail if the string object itself is offered as a parameter to FormatV. For example, the following code: 如果CString對象本身被當作參數(shù)提供給FormatV,那么函數(shù)會調(diào)用失敗。例如下面的代碼:CString str = "Some Data"str.Fo
32、rmatV("%s%d", str, 123);/ Attention: str is also used in the parameter list./注意:str也被用作參數(shù)will cause unpredictable results.將導致不可預知的結果。For more information, see vsprintf in the Run-Time Library Reference.更多說明參閱Run-Time Library Reference(運行庫參考手冊)中的vsprintf函數(shù)。 Example實例/Using CString:FormatV()
33、, you can write functions like the following:void WriteLogEntry(CStdioFile& refFile, LPCTSTR pstrFormat, .)CTime timeWrite;timeWrite = CTime:GetCurrentTime();/ write the time outCString str = timeWrite.Format("%d %b %y %H:%M:%S - ");refFile.Write(str, str.GetLength();/ format and write
34、 the data we were givenva_list args;va_start(args, pstrFormat);str.FormatV(pstrFormat, args);refFile.Write(str, str.GetLength();/ put a newlinerefFile.Write("n", 1);return;You can call the above function with any number of parameters, for example:WriteLogEntry(fileLog, "Program starte
35、d");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 the following:17 Apr 97 12:34:53 - Program
36、 started17 Apr 97 12:34:59 - Processed 91341 bytes17 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 lpszTargets );Parameters參數(shù)chTargetThe target characte
37、rs 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. Whenused with no parameters, TrimLeft removes newline
38、, space, and tab characters.該函數(shù)沒有參數(shù)的形式用來清除原對象前面的whitespace(百度了一下,whitespace 表示空格、制表符、回車等特殊字符,后面的說明正好證明了其含義)。不含參數(shù)的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.含有參數(shù)的該函數(shù)用來
39、清除原對象前面的指定的字符或字符集。For more information, see Strings Topics in Visual C+ Programmer's Guide更多說明參閱更加深入的編程話題(VC+程序員指南?)中的Strings Topics。Example實例In this example, the string "tt *Hockey is best!" becomes "Hockey is best!":下面的例子,字符串 "tt *Hockey is best!" 變成了 "Hockey
40、 is best!":CString strBefore;CString strAfter;strBefore = _T("tt *Hockey is best!");strAfter = strBefore;strAfter.TrimLeft(T_("t *");_tprintf(_T("Before: "%s"n"), (LPCTSTR) strBefore);_tprintf(_T("After : "%s"n"), (LPCTSTR) strAfter);M
41、SDN這里完全沒說清楚,自己補充(通過測試自己總結的,不一定對):沒有參數(shù)的形式已經(jīng)說清楚了,無須補充;有參數(shù)的兩種形式,前一種可以看作后一種的特例;接受字符串指針lpszTargets作為參數(shù)的形式,從原對象中找出第一個沒有在lpszTargets中出現(xiàn)的字符,將此字符及其之后的部分用來更新原對象。若原對象的第一個字符沒有在lpszTargets中出現(xiàn),則原對象不變;若原對象的所有字符都在lpszTargets中出現(xiàn),則原對象為空。該形式和CString:SpanIncluding類似,都是從原對象中找出第一個沒有在參數(shù)中出現(xiàn)的字符,只是前者用后面部分更新原對象,而后者是返回前面部分。-CS
42、tring:TrimRightvoid TrimRight( );void CString:TrimRight( TCHAR chTarget );void 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 ver
43、sion 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.該函數(shù)沒有參數(shù)的形式用來清除原對象后面的whitespace。不含參數(shù)的TrimRight清除換行,空格,制表符。Use the versions of this functi
44、on that accept parameters to remove a particular character or a particular group of characters from the end of a string.含有參數(shù)的該函數(shù)用來清除原對象后面的指定的字符或字符集。實際上就是從原對象最后面開始,向前找出第一個沒有在lpszTargets所指向的字符串中出現(xiàn)的字符,將該字符及其前面的部分用來更新原對象。更新后原對象有可能為空,也有可能不變。Example實例CString strBefore;CString strAfter;strBefore = "Ho
45、ckey is Best!"strAfter = strBefore;str.TrimRight('!');printf("Before: "%s"n", (LPCTSTR) strBefore);printf("After : "%s"nn", (LPCTSTR) strAfter);strBefore = "Hockey is Best?!?!?!?!"strAfter = strBefore;str.TrimRight("?!");printf
46、("Before: "%s"n", (LPCTSTR) strBefore);printf("After : "%s"nn", (LPCTSTR) strAfter);In the first example above, the string reading, "Hockey is Best!" becomes "Hockey is Best". 上面的第一個例子,原對象由"Hockey is Best!" 變成了 "Hockey is Bes
47、t"。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 lps
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度木飾面原材料進口與分銷合同3篇
- 2025年親子遺贈協(xié)議草案
- 2025年代理商代理加盟采購合資合作協(xié)議
- 2025年合資合作收益分配協(xié)議
- 2025年企業(yè)外包勞務協(xié)議
- 2025年智慧城市物業(yè)管理服務標準合同范本6篇
- 漫談加強物資管理提高企業(yè)經(jīng)濟效益-圖文
- 《皮質醇增多征荊》課件
- 2025年度醫(yī)院病理科診斷服務承包合同4篇
- 2025年度汽車轉讓及二手車交易稅費減免合同
- 個體工商戶章程(標準版)
- 廢舊物資買賣合同極簡版
- 2024年正定縣國資產(chǎn)控股運營集團限公司面向社會公開招聘工作人員高頻考題難、易錯點模擬試題(共500題)附帶答案詳解
- 智能衣服方案
- 李克勤紅日標準粵語注音歌詞
- 教科版六年級下冊科學第一單元《小小工程師》教材分析及全部教案(定稿;共7課時)
- 中藥材產(chǎn)地加工技術規(guī)程 第1部分:黃草烏
- 危險化學品經(jīng)營單位安全生產(chǎn)考試題庫
- 案例分析:美國紐約高樓防火設計課件
- 移動商務內(nèi)容運營(吳洪貴)任務一 用戶定位與選題
- 工作證明模板下載免費
評論
0/150
提交評論