MFC幾個關於字符串處理的全局函數

最近在使用字符資源的時候,發現有幾個全局函數處理字符串非常方便。
函數頭 void AFXAPI AfxFormatString1(CString& rString, UINT nIDS, LPCTSTR lpsz1);
函數功能 從資源文件裏讀取指定ID(nIDS)的資源字符串,並用字符串(lpsz1)替換資源字符串中出現的”%1”,假如”%1”出現多次,則多次替換。

函數頭 void AFXAPI AfxFormatString2(CString& rString, UINT nIDS,LPCTSTR lpsz1, LPCTSTR lpsz2);
函數功能 從資源文件裏讀取指定ID(nIDS)的資源字符串,並用字符串(lpsz1、lpsz2)替換資源字符串中出現的”%1”和”%2”,假如”%1”,”%2”出現多次,則多次替換,並且沒有次序上的限制。

函數頭 void AFXAPI AfxFormatStrings(CString& rString, LPCTSTR lpszFormat,
LPCTSTR const* rglpsz, int nString);
函數功能 用”%0-%9,%A-%Z”格式化字符串(lpszFormat),根據指定的上限(nSttring),分別從字符串數組(rglpsz)中取出對應索引的字符串替換之。如果數組長度或者上限限制對應的話,用”???”代替。
*
函數頭 void AFXAPI AfxFormatStrings(CString& rString, UINT nIDS,
LPCTSTR const* rglpsz, int nString);
函數功能 功能同上個函數,只不過被格式化的字符串來自資源ID(年IDS)
*
函數頭 BOOL AFXAPI AfxExtractSubString(CString& rString, LPCTSTR lpszFullString,int iSubString, TCHAR chSep = '/n');
函數功能 取出字符串(lpszFullString)中被字符(chSep)分割的第N(iSubString)個子字符串,並賦給字符串rString。返回值爲是否找到自字符串。
*
函數頭 int AFXAPI AfxLoadString(UINT nID, LPTSTR lpszBuf, UINT nMaxBuf)
函數功能 取出程序資源中ID爲nID的字符串,並賦給最大長度爲nMaxBuf的字符串(lpszBuf)。

函數頭 BOOL AFXAPI AfxParseURL(LPCTSTR pstrURL, DWORD& dwServiceType,CString& strServer, CString& strObject, INTERNET_PORT& nPort); 
函數功能 解析一個URL字符串,解析出服務類型(dwServiceType),服務器(strServer),附加目錄(strObject),端口號(nPort)。並返回解析成功與否。

函數頭 BOOL AFXAPI AfxParseURLEx(LPCTSTR pstrURL, 
DWORD& dwServiceType,CString& strServer, CString& strObject, 
INTERNET_PORT& nPort,CString& strUsername, CString& strPassword, 
DWORD dwFlags = 0);
函數功能 上一函數的功能擴展,能夠解析出用戶名和密碼,並且增加了解碼的控制(dwFlag),可以對字符串進行多種編解碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章