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.

141 lines
2.7 KiB
C

#pragma once
#include "GlobalDefine.h"
#include "BitOperation.h"
#define TRUE_STR _T("TRUE")
#define FALSE_STR _T("FALSE")
//<2F><>MFC CString <20><><EFBFBD>ص<EFBFBD>һЩ<D2BB><D0A9><EFBFBD><EFBFBD>
//ȥ<><C8A5>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>治Ҫ<E6B2BB><D2AA>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 ת<><D7AA>ΪCString (DigitsCnt <20><>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>,<2C><><EFBFBD><EFBFBD>== 6)
inline CString Db2CString(double n,int DigitsCnt = -1)
{
CString s;
if(DigitsCnt==0)
s.Format("%ld",(int)n);
if(DigitsCnt==1)
s.Format("%.1f",n);
if(DigitsCnt==2)
s.Format("%.2f",n);
if(DigitsCnt==3)
s.Format("%.3f",n);
if(DigitsCnt==4)
s.Format("%.4f",n);
if(DigitsCnt==5)
s.Format("%.5f",n);
if(DigitsCnt==6)
s.Format("%.6f",n);
if(DigitsCnt<0)
{
s.Format("%lf",n);
//ɾ<><C9BE>ĩβ<C4A9><CEB2>0
DeleteZero(s);
}
return s;
}
//int ת<><D7AA>ΪCString
inline CString Int2CString(int n)
{
CString s;
s.Format("%ld",n);
return s;
}
inline CString ByteToString(BYTE bit)
{
CString str;
for(int i=7;i>=0;i--)
{
if(IsBitOn(bit,i))
str += "1";
else
str += "0";
}
return str;
}
//<2F><>ȡbool <20><><EFBFBD>͵<EFBFBD>str
inline CString GetBoolValStr(bool b)
{
if(b)
return TRUE_STR;
else
return FALSE_STR;
}
//<2F><>str <20>в<EFBFBD><D0B2><EFBFBD>SubStr ,<2C>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>true
inline bool FindSubStr(CString &str,CString &SubStr)
{
return (str.Find(SubStr) != -1);
}
//ɾ<><C9BE><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ұߵIJ<DFB5><C4B2><EFBFBD>
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 CString Bool2CString(bool b)
{
if(b)
return "1";
else
return "0";
}
inline bool Str2Bool(CString &str)
{
if(str == _T("TRUE"))
return true;
else
return false;
}
inline CString Int2Str_LeftZero(int n)
{
CString s;
if(n<10)
s.Format("0%ld",n);//<2F><><EFBFBD>߲<EFBFBD>0
else
s.Format("%ld",n);
return s;
}
//<2F>ж<EFBFBD>String <20>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
inline bool IsStringDigit(CString s)
{
return (s.SpanIncluding("0123456789") == s);
}