﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-lanshengsheng-随笔分类-ftp客户端</title><link>http://www.cppblog.com/lanshengsheng/category/19958.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 25 Mar 2013 01:03:09 GMT</lastBuildDate><pubDate>Mon, 25 Mar 2013 01:03:09 GMT</pubDate><ttl>60</ttl><item><title>CString 成员函数用法大全  </title><link>http://www.cppblog.com/lanshengsheng/archive/2012/09/21/191444.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Fri, 21 Sep 2012 01:01:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2012/09/21/191444.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/191444.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2012/09/21/191444.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/191444.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/191444.html</trackback:ping><description><![CDATA[<strong>CString的构造函数</strong><wbr><wbr><br />CString( );<br />例：CString  csStr;<br /><br />CString( const CString&amp; stringSrc );<br />例：CString  csStr("ABCDEF中文123456");<br />&nbsp;&nbsp;&nbsp;&nbsp;CString csStr2(csStr);<br /><br />CString( TCHAR ch,  int nRepeat = 1 );<br />例：CString csStr('a',5);<br />//csStr="aaaaa"<wbr><br /><br />CString( LPCTSTR lpch, int nLength  );<br />例：CString csStr("abcdef",3);<br />//csStr="abc"<wbr><br /><br />CString( LPCWSTR lpsz  );<br />例：wchar_t s[]=L"abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;CString csStr(s);<br />//csStr=L"abcdef"<wbr><br /><br />CString( const unsigned char* psz  );<br />例：const unsigned char s[]="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;const unsigned char*  sp=s;<br />&nbsp;&nbsp;&nbsp;&nbsp;CString csStr(sp);<br />//csStr="abcdef"<wbr><br /><br />CString( LPCSTR lpsz  );<br />例：CString csStr("abcdef");<br />//csStr="abcdef"<wbr><br /><br /><strong><wbr>int  GetLength( )  const;</strong><wbr><wbr><br />返回字符串的长度，不包含结尾的空字符。<br />例：csStr="ABCDEF中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;printf("%d",csStr.GetLength());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //16<wbr><br /><br /><strong><wbr>void MakeReverse(  );</strong><wbr><wbr><br />颠倒字符串的顺序<br />例：csStr="ABCDEF中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.MakeReverse();<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//654321文中FEDCBA<wbr><br /><br /><strong><wbr>void MakeUpper(  );<wbr></strong><wbr><br />将小写字母转换为大写字母<br />例：csStr="abcdef中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.MakeUpper();<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//ABCDEF中文123456<wbr><br /><br /><strong><wbr>void MakeLower(  );</strong><wbr><wbr><br />将大写字母转换为小写字母<br />例：csStr="ABCDEF中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.MakeLower();<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//abcdef中文123456<wbr><br /><br /><strong><wbr>int Compare( LPCTSTR lpsz )  const;</strong><wbr><wbr><br />区分大小写比较两个字符串，相等时返回0，大于时返回1，小于时返回-1<br />例：csStr="abcdef中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr2="ABCDEF中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.CompareNoCase(csStr2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;//0<wbr><br /><br /><strong><wbr>int CompareNoCase( LPCTSTR lpsz )  const;</strong><wbr><wbr><br />不区分大小写比较两个字符串，相等时返回0，大于时返回1，小于时返回-1<br />例：csStr="abcdef中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr2="ABCDEF中文123456";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.CompareNoCase(csStr2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //-1<wbr><br /><br /><strong><wbr>int Delete( int nIndex, int nCount = 1  )</strong><wbr><wbr><br />删除字符，删除从下标nIndex开始的nCount个字符<br />例：csStr="ABCDEF";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.Delete(2,3);<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//  ABF<br />//当nIndex过大，超出对像所在内存区域时，函数没有任何操作。<br />//当nIndex为负数时，从第一个字符开始删除。<br />//当nCount过大，导致删除字符超出对像所在内存区域时，会发生无法预料的结果。<br />//当nCount为负数时，函数没有任何操作。<wbr><br /><br /><strong><wbr>int Insert(  int nIndex, TCHAR ch )<br />int Insert( int nIndex, LPCTSTR pstr  )</strong><wbr><wbr><br />在下标为nIndex的位置，插入字符或字符串。返回插入后对象的长度<br />例：csStr="abc";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.Insert(2,'x');<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //abxc<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;csStr="abc";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.Insert(2,"xyz");<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //abxyzc<wbr><br />//当nIndex为负数时，插入在对象开头<br />//当nIndex超出对象末尾时，插入在对象末尾<wbr><br /><br /><strong><wbr>int Remove(  TCHAR ch  );</strong><wbr><wbr><br />移除对象内的指定字符。返回移除的数目<br />例：csStr="aabbaacc";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.Remove('a');<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //bbcc<wbr><br /><br /><strong><wbr>int Replace( TCHAR chOld, TCHAR chNew );<br />int Replace(  LPCTSTR lpszOld, LPCTSTR lpszNew  );</strong><wbr><wbr><br />替换字串<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.Replace('a','x');<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//xbcdef<wbr><br />&nbsp;&nbsp;&nbsp;&nbsp;csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.Replace("abc","xyz");<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//xyzdef<wbr><br /><br /><strong><wbr>void TrimLeft( );<br />void TrimLeft( TCHAR  chTarget );<br />void TrimLeft( LPCTSTR lpszTargets  );</strong><wbr><wbr><br />从左删除字符，被删的字符与chTarget或lpszTargets匹配，一直删到第一个不匹配的字符为止<br />例：csStr="aaabaacdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.TrimLeft('a');<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//baacdef<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;csStr="aaabaacdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.TrimLeft("ab");<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//cdef<wbr><br />//无参数时删除空格<wbr><br /><br /><strong><wbr>void  TrimRight( );<br />void TrimRight( TCHAR chTarget );<br />void TrimRight( LPCTSTR  lpszTargets  );</strong><wbr><wbr><br />从右删除字符，被删的字符与chTarget或lpszTargets匹配，一直删到第一个不匹配的字符为止<br />例：csStr="abcdeaafaaa";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.TrimRight('a');<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //abcdeaaf<wbr><br />&nbsp;&nbsp;&nbsp;&nbsp;csStr="abcdeaafaaa";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.TrimRight("fa");<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//abcde<br />//无参数时删除空格<wbr><br /><br /><strong><wbr>void Empty(  );</strong><wbr><wbr><br />清空<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.Empty();<br />&nbsp;&nbsp;&nbsp;&nbsp;printf("%d",csStr.GetLength());&nbsp;&nbsp;&nbsp;&nbsp;//0<wbr><br /><br /><strong><wbr>BOOL IsEmpty( )  const;</strong><wbr><wbr><br />测试对象是否为空，为空时返回零，不为空时返回非零<br />例：csStr="abc";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.IsEmpty();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //0;<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;csStr.Empty();<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.IsEmpty();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //1;<wbr><br /><br /><strong><wbr>int Find( TCHAR ch ) const;<br />int Find(  LPCTSTR lpszSub ) const;<br />int Find( TCHAR ch, int nStart ) const;<br />int Find(  LPCTSTR pstr, int nStart )  const;</strong><wbr><wbr><br />查找字串，nStart为开始查找的位置。未找到匹配时返回-1，否则返回字串的开始位置<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Find('b');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //1<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Find("de");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//3<wbr><br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Find('b',3);&nbsp;&nbsp;&nbsp;&nbsp; //-1<wbr><br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Find('b',0);&nbsp;&nbsp;&nbsp;&nbsp; //1<wbr><br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Find("de",4);&nbsp;&nbsp;&nbsp;&nbsp;//-1<wbr><br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Find("de",0);&nbsp;&nbsp;&nbsp;&nbsp;//3<wbr><br />//当nStart超出对象末尾时，返回-1。<br />//当nStart为负数时，返回-1。<wbr><br /><br /><strong><wbr>int  FindOneOf( LPCTSTR lpszCharSet )  const;</strong><wbr><wbr><br />查找lpszCharSet中任意一个字符在CString对象中的匹配位置。未找到时返回-1，否则返回字串的开始位置<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.FindOneOf("cxy");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //2<wbr><br /><br /><strong><wbr>CString SpanExcluding( LPCTSTR lpszCharSet )  const;</strong><wbr><wbr><br />返回对象中与lpszCharSet中任意匹配的第一个字符之前的子串<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.SpanExcluding("cf");&nbsp;&nbsp;&nbsp;&nbsp;//ab<wbr><br /><br /><strong><wbr>CString SpanIncluding( LPCTSTR lpszCharSet )  const;</strong><wbr><wbr><br />从对象中查找与lpszCharSe中任意字符不匹配的字符，并返回第一个不匹配字符之前的字串<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.SpanIncluding("fdcba");&nbsp;&nbsp;&nbsp;&nbsp;//abcd<wbr><br /><br /><strong><wbr>int ReverseFind( TCHAR ch )  const;</strong><wbr><wbr><br />从后向前查找第一个匹配，找到时返回下标。没找到时返回-1<br />例：csStr="abba";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.ReverseFind('a');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//3<wbr><br /><br /><strong><wbr>void Format( LPCTSTR lpszFormat, ...  );<br />void Format( UINT nFormatID, ...  );</strong><wbr><wbr><br />格式化对象，与C语言的sprintf函数用法相同<br />例：csStr.Format("%d",13);<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //13<wbr><br /><br /><strong><wbr>TCHAR GetAt( int nIndex )  const;</strong><wbr><wbr><br />返回下标为nIndex的字符，与字符串的[]用法相同<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.GetAt(2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //c<br />//当nIndex为负数或超出对象末尾时，会发生无法预料的结果。<wbr><br /><br /><strong><wbr>void SetAt(  int nIndex, TCHAR ch  );</strong><wbr><wbr><br />给下标为nIndex的字符重新赋值<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.SetAt(2,'x');<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//abxdef<br />//当nIndex为负数或超出对象末尾时，会发生无法预料的结果。<wbr><br /><br /><strong><wbr>CString  Left( int nCount )  const;</strong><wbr><wbr><br />从左取字串<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Left(3);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //abc<br />//当nCount等于0时，返回空。<br />//当nCount为负数时，返回空。<br />//当nCount大于对象长度时，返回值与对象相同。<wbr><br /><br /><strong><wbr>CString  Right( int nCount )  const;</strong><wbr><wbr><br />从右取字串<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Right(3);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //def<br />//当nCount等于0时，返回空。<br />//当nCount为负数时，返回空。<br />//当nCount大于对象长度时，返回值与对象相同。<wbr><br /><br /><strong><wbr>CString  Mid( int nFirst ) const;<br />CString Mid( int nFirst, int nCount )  const;</strong><wbr><wbr><br />从中间开始取字串<br />例：csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Mid(2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //cdef<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;csStr="abcdef";<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.Mid(2,3);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //cde<br />//当nFirst为0和为负数时，从第一个字符开始取。<br />//当nFirst等于对象末尾时，返回空字串。<br />//当nFirst超出对象末尾时，会发生无法预料的结果。<br />//当nCount超出对象末尾时，返回从nFirst开始一直到对象末尾的字串<br />//当nCount为0和为负数时，返回空字串。<wbr><br /><br /><strong><wbr>LPTSTR  GetBuffer( int nMinBufLength  );</strong><wbr><wbr><br />申请新的空间，并返回指针<br />例：csStr="abcde";<br />&nbsp;&nbsp;&nbsp;&nbsp;LPTSTR  pStr=csStr.GetBuffer(10);<br />&nbsp;&nbsp;&nbsp;&nbsp;strcpy(pStr,"12345");<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.ReleaseBuffer();<br />&nbsp;&nbsp;&nbsp;&nbsp;pStr=NULL;<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //12345<br />//使用完GetBuffer后，必须使用ReleaseBuffer以更新对象内部数据，否则会发生无法预料的结果。<wbr><br /><br /><strong><wbr>void  ReleaseBuffer( int nNewLength = -1  );</strong><wbr><wbr><br />使用GetBuffer后，必须使用ReleaseBuffer以更新对象内部数据<br />例：csStr="abc";<br />&nbsp;&nbsp;&nbsp;&nbsp;LPTSTR  pStr=csStr.GetBuffer(10);<br />&nbsp;&nbsp;&nbsp;&nbsp;strcpy(pStr,"12345");<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.GetLength();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //3(错误的用法)<wbr><br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.ReleaseBuffer();<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr.GetLength();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //5(正确)<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;pStr=NULL;<br />//CString对象的任何方法都应在ReleaseBuffer之后调用<wbr><br /><br /><strong><wbr>LPTSTR  GetBufferSetLength( int nNewLength  );</strong><wbr><wbr><br />申请新的空间，并返回指针<br />例：csStr="abc";<br />&nbsp;&nbsp;&nbsp;&nbsp;csStr.GetBufferSetLength(20);<br />&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;csStr;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//abc<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;count&lt;&lt;csStr.GetLength();&nbsp;&nbsp;&nbsp;&nbsp;  //20;<br /><wbr>&nbsp;&nbsp;&nbsp;&nbsp;csStr.ReleaseBuffer();<br />&nbsp;&nbsp;&nbsp;&nbsp;count&lt;&lt;csStr.GetLength();&nbsp;&nbsp;&nbsp;&nbsp;  //3;<br />//使用GetBufferSetLength后可以不必使用ReleaseBuffer。<br /><br /><br /><br />CString ImagePath = "d:/abc/dd.avi";<br /><div><span style="white-space:pre">		</span>int i = ImagePath.ReverseFind(_T('/'));</div><div><span style="white-space:pre">		</span>CString strtest = ImagePath.Left(i+1);</div><br /><br /><div>pasting</div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/191444.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2012-09-21 09:01 <a href="http://www.cppblog.com/lanshengsheng/archive/2012/09/21/191444.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>_tcscmp 与strcmp区别</title><link>http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191398.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Thu, 20 Sep 2012 07:15:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191398.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/191398.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191398.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/191398.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/191398.html</trackback:ping><description><![CDATA[<br />int _stricmp(    const char *string1,    const char *string2  );&nbsp;<span style="color: #454545; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; background-color: #ffffff; ">strcmp 用来比较ANSI字符串，而</span><strong style="color: #454545; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; background-color: #ffffff; ">_tcscmp</strong><span style="color: #454545; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; background-color: #ffffff; ">用 来比较UNICODE（宽字符）的字符串。ANSI字符串中，1个英文字母为1个字节，1个中文字符为2个字节，遇到0字符表示字符串结束。而在 UNICODE（宽字符）中，所有的字符都为2个字节，此时字符串中间的字节，可能含有0字符，此时就不能用strcmp比较了。</span><br style="color: #454545; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; background-color: #ffffff; " /><br style="color: #454545; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; background-color: #ffffff; " /><span style="color: #454545; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; background-color: #ffffff; ">strcmp(char *s1, char *s2) : 按照各个字符（ascii）比较s1和s2，相等则返回0，否则返回ascii相减的结果。<br /></span><pre>int _stricmp(
   const char *<span class="parameter">string1</span>,
   const char *<span class="parameter">string2</span> 
);
</pre><table cellspacing="2" cellpadding="5" width="50%" frame="lhs">
<tbody>
<tr>
<th>
<p>Return value</p></th>
<th>
<p>Description</p></th></tr>
<tr>
<td>
<p>&lt; 0</p></td>
<td>
<p><span class="parameter">string1</span> less than <span class="parameter">string2</span></p></td></tr>
<tr>
<td>
<p>0</p></td>
<td>
<p><span class="parameter">string1</span> identical to <span class="parameter">string2</span></p></td></tr>
<tr>
<td>
<p>&gt; 0</p></td>
<td>
<p><span class="parameter">string1</span> greater than <span class="parameter">string2</span></p></td></tr></tbody></table><span style="color: #454545; font-family: 'Microsoft Yahei', 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; line-height: normal; background-color: #ffffff; "><br /><br /></span><img src ="http://www.cppblog.com/lanshengsheng/aggbug/191398.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2012-09-20 15:15 <a href="http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191398.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CFileDialog文件选择对话框的使用</title><link>http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191344.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Thu, 20 Sep 2012 01:55:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191344.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/191344.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191344.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/191344.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/191344.html</trackback:ping><description><![CDATA[<span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">CFileDialog</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">文件选择对话框的使用：首先构造一个对象并提供相应的参数，构造函数原型如下：</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">CFileDialog::CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );</span><br style="line-height: 22px; font-family: simsun; " /><br />例子：CFileDialog mFileDlg(FALSE, NULL, NULL, OFN_ALLOWMULTISELECT,&nbsp;_T("所有文件 (*.*)|*.*||"), this);&nbsp;<br /><br style="line-height: 22px; font-family: simsun; " /><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">参数意义如下：</span><br style="line-height: 22px; font-family: simsun; " /><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">bOpenFileDialog 为TRUE则显示打开对话框，为FALSE则显示保存对话文件对话框。</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">lpszDefExt 指定默认的文件扩展名。</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">lpszFileName 指定默认的文件名。</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">dwFlags 指明一些特定风格。</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">lpszFilter 是最重要的一个参数，它指明可供选择的文件类型和相应的扩展名。参数格式如：</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|*.xlc; *.xls|All Files (*.*)|*.*||";文件类型说明和扩展名间用 | 分隔，同种类型文件的扩展名间可以用 ; 分割，每种文件类型间用 | 分隔，末尾用 || 指明。</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">pParentWnd 为父窗口指针。</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">创建文件对话框可以使用DoModal()，在返回后可以利用下面的函数得到用户选择：</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">CString CFileDialog::GetPathName( ) 得到完整的文件名，包括目录名和扩展名如：c: est est1.txt</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">CString CFileDialog::GetFileName( ) 得到完整的文件名，包括扩展名如：test1.txt</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">CString CFileDialog::GetExtName( ) 得到完整的文件扩展名，如：txt</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">CString CFileDialog::GetFileTitle ( ) 得到完整的文件名，不包括目录名和扩展名如：test1</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">POSITION CFileDialog::GetStartPosition( ) 对于选择了多个文件的情况得到第一个文件位置。</span><br style="line-height: 22px; font-family: simsun; " /><span style="margin: 0px; padding: 0px; line-height: 22px; font-family: simsun; ">CString CFileDialog::GetNextPathName( POSITION&amp; pos ) 对于选择了多个文件的情况得到下一个文件位置，并同时返回当前文件名。但必须已经调用过POSITION CFileDialog::GetStartPosition( )来得到最初的POSITION变量。</span><img src ="http://www.cppblog.com/lanshengsheng/aggbug/191344.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2012-09-20 09:55 <a href="http://www.cppblog.com/lanshengsheng/archive/2012/09/20/191344.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>