You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
1.8 KiB
C
99 lines
1.8 KiB
C
#pragma once
|
|
#include "GlobalDefine.h"
|
|
|
|
#define TRUE_STR _T("TRUE")
|
|
#define FALSE_STR _T("FALSE")
|
|
//和MFC CString 相关的一些函数
|
|
|
|
//去掉小数点后面不要的0
|
|
inline void DeleteZero(CString &s)
|
|
{
|
|
int nIndex;
|
|
nIndex=s.Find('.');
|
|
if (nIndex>=0)
|
|
{
|
|
s.TrimRight('0');
|
|
if (s.GetLength()==nIndex+1)
|
|
{
|
|
s=s.Left(nIndex);
|
|
if (s.IsEmpty())
|
|
s='0';
|
|
}
|
|
}
|
|
}
|
|
|
|
//double 转换为CString
|
|
inline CString Db2CString(double n)
|
|
{
|
|
CString s;
|
|
s.Format("%lf",n);
|
|
DeleteZero(s);
|
|
return s;
|
|
}
|
|
//int 转换为CString
|
|
inline CString Int2CString(int n)
|
|
{
|
|
CString s;
|
|
s.Format("%ld",n);
|
|
return s;
|
|
}
|
|
//获取bool 类型的str
|
|
inline CString GetBoolValStr(bool b)
|
|
{
|
|
if(b)
|
|
return TRUE_STR;
|
|
else
|
|
return FALSE_STR;
|
|
}
|
|
//在str 中查找SubStr ,找到返回true
|
|
inline bool FindSubStr(CString &str,CString &SubStr)
|
|
{
|
|
return (str.Find(SubStr) != -1);
|
|
}
|
|
//删除子串,并返回剩余右边的部分
|
|
inline CString DelSubStr(CString str,CString &SubStr)
|
|
{
|
|
int pos = str.Find(SubStr);
|
|
if(pos != -1)
|
|
{
|
|
str = str.Right(str.GetLength()-(pos+SubStr.GetLength()));
|
|
}
|
|
return str;
|
|
}
|
|
inline int CStringToInt(CString &str)
|
|
{
|
|
return _tstoi(LPCTSTR(str));
|
|
}
|
|
inline double CStringToDouble(CString &str)
|
|
{
|
|
return _tstof(LPCTSTR(str));
|
|
}
|
|
inline bool CStringToBool(CString &str)
|
|
{
|
|
if(str == TRUE_STR)
|
|
return true;
|
|
return false;
|
|
}
|
|
inline CString Bool2Str(bool b)
|
|
{
|
|
if(b)
|
|
return "TRUE";
|
|
else
|
|
return "FALSE";
|
|
}
|
|
inline bool Str2Bool(CString &str)
|
|
{
|
|
if(str == _T("TRUE"))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
inline CString Time2Str(int n)
|
|
{
|
|
CString s;
|
|
if(n<10)
|
|
s.Format("0%ld",n);//左边补0
|
|
else
|
|
s.Format("%ld",n);
|
|
return s;
|
|
} |