📄 jnstring.cpp
字号:
str.Insert(str.GetLength(),charAt);
}
str1=str;
/*
int nLenght=sMima.GetLength();
char charAt;
int nNum=32;
for(int i=0;i<nLenght;i++)
{
charAt=sMima.GetAt(i);
nNum+=(int)charAt;
}
nLenght=str1.GetLength();
BOOL bCk=FALSE;
for(i=0;i<nLenght;i++)
{
if(bCk)
str1.SetAt(i,str1.GetAt(i)+nNum+i+37);
else
str1.SetAt(i,str1.GetAt(i)-nNum-i-37);
}*/
return str1;
}
/***************************************************************************
函数名称:TransAdoToDb
函数功能:根据数据源把ado类型的变量转换成对应数据库中的类型
函数原理:
****************************************************************************/
CString JnString::TransAdoToDb(UINT adoType,int nLenght,CString& sDbEngine)
{
CString sRet=_T("");
if(sDbEngine==_T("Access97"))
{
switch(adoType)
{
case adTinyInt: //1-byte有符号整数
case adUnsignedTinyInt: //1-byte无符号整数(Byte)
sRet=_T("BYTE");
sRet+=_T(" NULL");
break;
case adSmallInt: //2-byte有符号Integer整数
case adUnsignedSmallInt: //2-byte无符号整数
sRet=_T("SHORT");
sRet+=_T(" NULL");
break;
case 1:
case adInteger: //4-byte有符号long整数
case adUnsignedInt: //4-byte无符号整数
case adDecimal: //指定精度和进度的数值
case adNumeric: //指定精度和进度的数值
case adVarNumeric: //指出一个数字,仅适用于Parameter对象
case adBigInt: //8-byte有符号整数
case adUnsignedBigInt: //8-byte无符号整数
sRet=_T("LONG");
sRet+=_T(" NULL");
break;
case adSingle: //Single-precision(单精度)浮点数
sRet=_T("SINGLE");
sRet+=_T(" NULL");
break;
case adDouble: //Double-precision(双精度)浮点数
sRet=_T("DOUBLE");
sRet+=_T(" NULL");
break;
case adCurrency: //Currency值是带有4个小数位的数值,它存储了一个以1000个数来分隔的8-byte有符号整数
sRet=_T("CURRENCY");
sRet+=_T(" NULL");
break;
case adBoolean: //布尔类型
sRet=_T("BIT");
sRet+=_T(" NULL");
break;
case adDate: //Date值,以Double形式存储,整数部分表示1899年12月30日以来的天数,小数部分表示一天的多少分之几
case adDBDate: //日期值,格式为yyyymmdd
case adDBTime: //时间值,格式为hhmmss
case adDBTimeStamp: //时间戳,格式为yyyymmddhhmmss外加纳秒数
case adFileTime: //以64位宽度表示时间值
// case adDBFileTime:
sRet=_T("DATETIME");
sRet+=_T(" NULL");
break;
case adError: //32位错误码
case adUserDefined: //用户自定义变量
case adVariant: //Automation(VBA)Variant
case adIDispatch: //指向OLE对象的IDispatch接口的指针
case adIUnknown: //指向OLE对象的IUnknown接口的指针
case adGUID: //全局唯一标识符GUID
case adEmpty: //无指定值
case adBSTR: //以NULL结尾的Unicode字符串
case adChar: //String值
case adVarChar: //String值,仅适用于Parameter对象
case adLongVarChar: //大于255字符的String值,仅适用于Parameter对象
case adWChar: //以NULL结尾的Unicode字符串
case adVarWChar: //以NULL结尾的Unicode字符串,仅适用于Parameter对象
sRet=_T("TEXT");
sRet+=_T(" (");
sRet+=IntToStr1(nLenght);
sRet+=_T(")");
sRet+=_T(" NULL");
break;
case adLongVarWChar: //以NULL结尾的长字符串,仅适用于Parameter对象
sRet=_T("LONGTEXT");
sRet+=_T(" (");
sRet+=IntToStr1(nLenght);
sRet+=_T(")");
sRet+=_T(" NULL");
break;
case adBinary: //二进制值
case adVarBinary: //二进制值,仅适用于Parameter对象
case adLongVarBinary: //长二进制值,仅适用于Parameter对象
case adChapter: //标识一个chapterd rowset或含有一个子Recordset的层次型Recordset的字段
case adPropVariant: //指出Indicates an Automation PROPVARIANT
sRet=_T("LONGBINARY");
sRet+=_T(" (");
sRet+=IntToStr1(nLenght);
sRet+=_T(")");
sRet+=_T(" NULL");
break;
default:
break;
}
}
else if(sDbEngine==_T("Sql-Server70"))
{
switch(adoType)
{
case adTinyInt: //1-byte有符号整数
case adUnsignedTinyInt: //1-byte无符号整数(Byte)
sRet=_T("tinyint");
sRet+=_T(" NULL");
break;
case adSmallInt: //2-byte有符号Integer整数
case adUnsignedSmallInt: //2-byte无符号整数
sRet=_T("smallint");
sRet+=_T(" NULL");
break;
case 1:
case adInteger: //4-byte有符号long整数
case adUnsignedInt: //4-byte无符号整数
sRet=_T("int");
sRet+=_T(" NULL");
break;
case adDecimal: //指定精度和进度的数值
sRet=_T("decimal");
sRet+=_T(" NULL");
break;
case adNumeric: //指定精度和进度的数值
case adVarNumeric: //指出一个数字,仅适用于Parameter对象
sRet=_T("numeric");
sRet+=_T(" NULL");
break;
case adBigInt: //8-byte有符号整数
case adUnsignedBigInt: //8-byte无符号整数
sRet=_T("float");
sRet+=_T(" NULL");
break;
case adSingle: //Single-precision(单精度)浮点数
case adCurrency: //Currency值是带有4个小数位的数值,它存储了一个以1000个数来分隔的8-byte有符号整数
sRet=_T("real");
sRet+=_T(" NULL");
break;
case adDouble: //Double-precision(双精度)浮点数
sRet=_T("float");
sRet+=_T(" NULL");
break;
case adBoolean: //布尔类型
sRet=_T("bit");
sRet+=_T(" NULL");
break;
case adDate: //Date值,以Double形式存储,整数部分表示1899年12月30日以来的天数,小数部分表示一天的多少分之几
case adDBDate: //日期值,格式为yyyymmdd
case adDBTime: //时间值,格式为hhmmss
case adDBTimeStamp: //时间戳,格式为yyyymmddhhmmss外加纳秒数
case adFileTime: //以64位宽度表示时间值
// case adDBFileTime:
sRet=_T("datetime");
sRet+=_T(" NULL");
break;
case adError: //32位错误码
case adUserDefined: //用户自定义变量
case adVariant: //Automation(VBA)Variant
case adIDispatch: //指向OLE对象的IDispatch接口的指针
case adIUnknown: //指向OLE对象的IUnknown接口的指针
case adGUID: //全局唯一标识符GUID
case adEmpty: //无指定值
case adBSTR: //以NULL结尾的Unicode字符串
case adChar: //String值
case adVarChar: //String值,仅适用于Parameter对象
case adLongVarChar: //大于255字符的String值,仅适用于Parameter对象
case adWChar: //以NULL结尾的Unicode字符串
case adVarWChar: //以NULL结尾的Unicode字符串,仅适用于Parameter对象
sRet=_T("nvarchar");
sRet+=_T(" (");
sRet+=IntToStr1(nLenght);
sRet+=_T(")");
sRet+=_T(" NULL");
break;
case adLongVarWChar: //以NULL结尾的长字符串,仅适用于Parameter对象
sRet=_T("text");
sRet+=_T(" (");
sRet+=IntToStr1(nLenght);
sRet+=_T(")");
sRet+=_T(" NULL");
break;
case adBinary: //二进制值
case adVarBinary: //二进制值,仅适用于Parameter对象
case adLongVarBinary: //长二进制值,仅适用于Parameter对象
case adChapter: //标识一个chapterd rowset或含有一个子Recordset的层次型Recordset的字段
case adPropVariant: //指出Indicates an Automation PROPVARIANT
sRet=_T("binary");
sRet+=_T(" (");
sRet+=IntToStr1(nLenght);
sRet+=_T(")");
sRet+=_T(" NULL");
break;
default:
break;
}
}
else
{
sRet=_T("");
}
return sRet;
}
CString JnString::NumberString(CString str, int nNum)
{
int n=StrToInt1(str);
str=IntToStr1(n);
int n1=nNum-str.GetLength();
if(n1>=0)
{
for(int i=0;i<n1;i++)
{
str.Insert(0,_T("0"));
}
}
else
{
str.Delete(str.GetLength()-1+n1,n1);
}
return str;
}
CString JnString::GetStrLeft1(CString str, CString sFind)
{
int n;
LPTSTR pstr=NULL;
pstr=CStringToLPTSTR(sFind);
n=str.Find(pstr);
if(n>-1)
{
str=str.Left(n);
}
return str;
}
/***************************************************************************
函数名称:VerifyString
函数功能:校验str中的每个字符是不是s1字符数组中定义的字符,如果不是,则返回FALSE
函数原理:
****************************************************************************/
BOOL JnString::VerifyString(CString& str)
{
int n1=0;
int n2=0;
char vch;
char s1[12];
s1[0]='0';
s1[1]='1';
s1[2]='2';
s1[3]='3';
s1[4]='4';
s1[5]='5';
s1[6]='6';
s1[7]='7';
s1[8]='8';
s1[9]='9';
s1[10]='.';
s1[11]='-';
BOOL bCk=FALSE;
for(int i=0;i<str.GetLength();i++)
{
bCk=FALSE;
vch=str.GetAt(i);
for(int j=0;j<12;j++)
{
if(s1[j]==vch)
{
if(vch=='-')
{
n1++;
}
if(vch=='.')
{
n2++;
}
bCk=TRUE;
break;
}
}
if(!bCk)
{
return FALSE;
}
}
if(n1>1 || n2>1)
return FALSE;
return TRUE;
}
CString JnString::Jiami2(CString str)
{
// CString sMagic="L5WXTUYJH7VMB4GA8SFKQN9E36RPDC";
CString sMagic=_T("251KBPNYZX");
CString str1,str2;
str2=_T("");
int nLenght=str.GetLength();
int nSum=0;
for(int i=0;i<nLenght;i++)
{
str1=str.GetAt(i);
nSum+=StrToInt1(str1);
str2+=sMagic.GetAt(StrToInt1(str1));
}
str1=IntToStr1(nSum);
str1=str1.GetAt(str1.GetLength()-1);
str2.Insert(0,sMagic.GetAt(StrToInt1(str1)));
/* string sResult="";//"FFTN-";
long lSum=0;
long lSum1;
long lChksum;
register unsigned int i;
// Calculate the registration string
for(i=0;i<sName.length();i++){
lSum += sName.at(i) * (i+1);
}
// The checksum prevents accident input
lChksum=sMagic.at(lSum%30);
sResult+=sMagic.at(lSum%30);
lSum1=lSum;
for(i=0;i<4;i++){
sResult+=(char)((lSum%10)+'0');
lChksum+=((lSum%10)+'0');
lSum/=10;
}
sResult+=(sMagic.at(lChksum%30));*/
return str2;
}
CString JnString::Jiemi2(CString str)
{
CString sMagic=_T("251KBPNYZX");
CString str1=_T(""),str2=_T(""),str3=_T(""),str4=_T("");
str1=str.GetAt(0);
int nSum=0;
for(int i=0;i<sMagic.GetLength();i++)
{
str2=sMagic.GetAt(i);
if(str1==str2)
{
str3=IntToStr1(i);
break;
}
}
str.Delete(0);
for(i=0;i<str.GetLength();i++)
{
str1=str.GetAt(i);
for(int j=0;j<sMagic.GetLength();j++)
{
str2=sMagic.GetAt(j);
if(str1==str2)
{
str.Delete(i);
str.Insert(i,IntToStr1(j));
break;
}
}
}
for(i=0;i<str.GetLength();i++)
{
nSum+=StrToInt1(str.GetAt(i));
}
str4=IntToStr1(nSum);
str4=str4.GetAt(str4.GetLength()-1);
if(str3!=str4)
str=_T("");
return str;
}
CString JnString::GetStrLeft(CString str, CString sFind, int nType)
{
int n;
if(nType==0)
{
n=str.Find(CStringToLPTSTR(sFind));
if(n>-1)
{
str=str.Left(n);
return str;
}
else
{
return _T("");
}
}
else if(nType==1)
{
n=str.Find(CStringToLPTSTR(sFind));
if(n>-1)
str=str.Left(n);
return str;
}
return _T("");
}
void JnString::GetStrFind1(CStringArray &array, CString sText, CString sFind)
{
array.RemoveAll();
CString str1;
while(sText.GetLength()>0)
{
str1=_T("");
LPTSTR pstr=NULL;
pstr=CStringToLPTSTR(sFind);
int nIndex = sText.Find(pstr);
if(nIndex==-1)
{
str1=sText;
sText=_T("");
}
else
{
nIndex++;
str1=sText.Left(nIndex);
sText=sText.Right(sText.GetLength()-nIndex);
}
str1.Replace(pstr,"");
str1.Replace("'","");
if(str1!="")
array.Add(str1);
// if(pstr)
// {
// delete pstr;
// pstr=NULL;
// }
}
}
CString JnString::AryToStr(CStringArray &array, CString str)
{
CString sRet=_T("");
for(int i=0;i<array.GetSize();i++)
{
sRet+=array.GetAt(i);
sRet+=str;
}
sRet=sRet.Left(sRet.GetLength()-str.GetLength());
return sRet;
}
CString JnString::DoubleToStr(double d)
{
CString str;
str.Format("%.2f",d);
return str;
}
CString JnString::GetDir(CString sPath)
{
CStringArray array;
GetStrFind1(array,sPath,_T("\\"));
sPath="";
if(array.GetSize()>1)
{
for(int i=0;i<array.GetSize()-1;i++)
{
sPath+=array.GetAt(i);
sPath+=_T("\\");
}
}
sPath.Delete(sPath.GetLength()-1);
return sPath;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -