关于MFC的一些数据之间的转换与提取

参考: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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值