人生本是一个不断学习的过程,在这个过程中,图老师就是你们的好帮手,下面分享的MFC中几个有用的字符串操作函数懂设计的网友们快点来了解吧!
【 tulaoshi.com - 编程语言 】
MFC中有几个字符串操作函数很有用,但有的在MSDN中都查不到,因为MSDN没有公布。下面我们来看看它们的用法和声明及定义等。// 功能 : 格式化字符串
  // 参数 : rString - 输出参数,格式化后的字符串将保存在此字符串中
    ![]()
![]()
![]()
![]() !-- frame contents --   !-- /frame contents --
!-- frame contents --   !-- /frame contents --![]()
![]()
![]()
![]() // nIDS - 将进行替换操作的格式字符串的资源ID
  // nIDS - 将进行替换操作的格式字符串的资源ID
  // lpsz1 - 指向将替换格式字符串中“%1”字符的字符串
  // lpsz2 - 指向将替换格式字符串中“%2”字符的字符串
  void AFXAPI AfxFormatString1(CString& rString, UINT nIDS, LPCTSTR lpsz1);
  void AFXAPI AfxFormatString2(CString& rString, UINT nIDS, LPCTSTR lpsz1, LPCTSTR lpsz2);
  // Implementation string helpers
  void AFXAPI AfxFormatStrings(CString& rString, UINT nIDS, LPCTSTR const* rglpsz, int nString);
  void AFXAPI AfxFormatStrings(CString& rString, LPCTSTR lpszFormat, LPCTSTR const* rglpsz, int nString);
  // 功能 : 获取子字符串
  // 参数 : rString - 输出参数,保存子字符串
  // lpszFullString - 源字符串 
  // iSubString - 子字符串索引,从0开始计数
  // chSep - 子字符串间的分隔字符,默认为''
  BOOL AFXAPI AfxExtractSubString(CString& rString, LPCTSTR lpszFullString, int iSubString, TCHAR chSep = '');
  /////////////////////////////////////////////////
  ////////////////////////////////////////////////
  ///
  // Strings in format ".....%1 .... %2 ...." etc. void AFXAPI AfxFormatStrings(CString& rString, UINT nIDS,
  LPCTSTR const* rglpsz, int nString)
  {
  TCHAR szFormat[256];
  if (!AfxLoadString(nIDS, szFormat) != 0)
  {
  TRACE1("Error: failed to load AfxFormatString string 0x%04x.", nIDS);
  ASSERT(FALSE);
  return;
  }
  AfxFormatStrings(rString, szFormat, rglpsz, nString);
  }
  
  void AFXAPI AfxFormatStrings(CString& rString, LPCTSTR lpszFormat,
  LPCTSTR const* rglpsz, int nString)
  {
  // 计算结果字符串的长度
  int nTotalLen = 0;
  LPCTSTR pchSrc = lpszFormat;
  while (*pchSrc != '
                        来源:http://www.tulaoshi.com/n/20160219/1618123.html
看过《MFC中几个有用的字符串操作函数》的人还看了以下文章 更多>>