關於MFC的一些資料之間的轉換與提取
阿新 • • 發佈:2018-11-15
參考:http://blog.sina.com.cn/s/blog_50eb38e00100ad5z.html
CString到DWORD
CString str="127.0.0.1";
char *szServerAddress = str.GetBuffer(0);
str.ReleaseBuffer();
DWORD dwRemoteIPValue = inet_addr(szServerAddress);
int到CString
int m=5
str.Format("%d",m);個人理解應該是double而不是int,如果是float,則只需將d改為f便是
例程1:(csdn)
檔案xxxx.dll去掉後面的.dll
方法1、
char str[] = "xxxx.dll"
char*p;
p=strrchr(str, '.');
*p = 0;
方法2、
CString str="xxxx.dll";
int n = str.ReverseFind('.')
str = str.Left(str.GetLength()-n-1);
例程2:(csdn)
取得一個字串中第一個 '?'號之前的字元
方法1
CString m_char,m_disp;
m_disp="jadfueiuajdf?";
m_char="?";
if (!m_char.IsEmpty())
{
int index = m_disp.Find(m_char);
m_disp = m_disp.Right(m_disp.GetLength()-index-1);
}
返回m_disp就行
方法2
CString temp=the.m_bb;
CString reslut=temp.Left(temp.Find("?")-1);
例程3:(csdn)
一個CString類物件m_StrReceiveModem={ATS0=2
OK
$03#}
如何擷取從$開始的字串
方法1
CString m_StrReceiveModem;
int nPos = m_StrReceiveModem.Find('$');
if(nPos >= 0)
{
CString sSubStr =m_StrReceiveModem.Mid(nPos);//包含$,不想包含時nPos+1
}
方法2
CString m_StrReceiveModem;
int nPos = m_StrReceiveModem.Find('$');
if(nPos >= 0)
{
CString sSubStr =m_StrReceiveModem.Right(StrReceiveModem.GetLength()-nPos);
}