登录 用户中心() [退出] 后台管理 注册
 

热门搜索:
您的位置:首页 >> 马上代码 >> 马上代码 >> 主题: 中文及特殊编码SQL代码专用
标题 中文及特殊编码SQL代码专用
我是马甲
浏览(1758) 2007-05-24 16:17:07 发表 编辑

关键字:

中文及特殊编码SQL代码专用

至于怎么用嘛 :) 呵呵

std::string MBCS_decode(const std::string s)
{

int i1,len1;
char c1;
//unsigned char b1;
int byte_ord1;//当前字节在多字节中的位置
std::string b_s1;//表示一个字节16进制的字符串
char tag1;//分隔标识


std::string result ="";//天哪这个是一定要有的,否则 result 中的内容有可能仍然上次执行后的结果

len1 =s.size();
byte_ord1 =0;
b_s1 ="";
tag1 ='a';//分隔标识

for (i1 =1; i1 < len1; i1++)
{
c1 =s[i1];
if (c1 == tag1) continue;

b_s1 = b_s1+c1;

if (b_s1.size() == 2)
{
//b_s1 = '$'+b_s1;
//result:=result+char(strtointdef(b_s1,0));
result = result + hex_to_str(b_s1);

b_s1 = "";
}

}

return result;
}

我是马甲
2007-5-24 16:17:27 发表 编辑

//["63"]=>["c"]
std::string hex_to_str(std::string s)
{
if ((s.size() % 2)!=0)//必须是2的倍数
{
printfd2("error at hex_to_str():%s\r\n", s.c_str());
return "";
}

char buf[3];
memset(buf, 0, sizeof(buf));

std::string r = "";
char c1,c2;
int i1,i2;
for(int i=0; i {
c1 = s[i];
c2 = s[i+1];
i1 = hexchar_to_int(c1);
i2 = hexchar_to_int(c2);

if ((i1==-1)||(i2==-1))
{
printfd2("error at hex_to_str()2:%s\r\n", s.c_str());
return "";
}


r += ( (char)(i1*16 + i2) );

i += 2;
}

return r;

}

我是马甲
2007-5-24 16:18:26 发表 编辑

std::string str_to_hex(std::string s)
{
char buf[3];
memset(buf, 0, sizeof(buf));

std::string r = "";
char c;
for(int i=0; i {
c = s[i];
sprintf(buf, "%X", (byte)c);
r += buf;
}

return r;

//return ucase(r);
}

我是马甲
2007-5-24 16:21:03 发表 编辑

其实这是从delphieadc转换而来的.

class function MBCS_encode(const s:string):string;
var
i1:integer;
len1:integer;
b1:byte;
byte_ord1:integer;//当前字节在多字节中的位置
tag1:char;//分隔标识
begin
//access 的 '#' 在like中另有用途,所以用字母 'a' 来代替好了//另外文件名在不同的 windows 下大小写的处理是有所不同的,所以要先转换为小写
result:='';//天哪这个是一定要有的,否则 result 中的内容有可能仍然上次执行后的结果
len1:=length(s);
byte_ord1:=0;
tag1:='a';//分隔标识

for i1:=1 to len1 do
begin
b1:=ord(s[i1]);
if b1>129 then
begin
byte_ord1:=byte_ord1+1;
if byte_ord1=1 then result:=result+ tag1;
if byte_ord1=2 then byte_ord1:=0;

result:=result+inttohex(b1,2);
end
else//一般的字符
begin
byte_ord1:=0;
result:=result + tag1 + inttohex(b1,2);
end;

end;
end;

class function MBCS_decode(const s:string):string;
var
i1:integer;
len1:integer;
c1:char;
b1:byte;
byte_ord1:integer;//当前字节在多字节中的位置
b_s1:string;//表示一个字节16进制的字符串
tag1:char;//分隔标识

begin
result:='';//天哪这个是一定要有的,否则 result 中的内容有可能仍然上次执行后的结果
len1:=length(s);
byte_ord1:=0;
b_s1:='';
tag1:='a';//分隔标识

for i1:=1 to len1 do
begin
c1:=s[i1];
if c1=tag1 then continue;
b_s1:=b_s1+c1;

if length(b_s1)=2 then
begin
b_s1:='$'+b_s1;
result:=result+char(strtointdef(b_s1,0));

b_s1:='';
end;

end;
end;


delphi语言还是比较强悍的.


总数:3 页次:1/1 首页 尾页  


发表评论:
文本/html模式切换 插入图片 文本/html模式切换


附件:




Copyright © 2005-2012 CLQ工作室, All Rights Reserved

CLQ工作室 版权所有