易截截图软件、单文件、免安装、纯绿色、仅160KB

Delphi中实现全角转半角

Delphi中实现全角转半角
function SbctoDbc(s:string):string;
var
 
nlength,i:integer;
  str,ctmp,c1,c2:string;
 
{
 在windows中,中文和全角字符都占两个字节,
 并且使用了ascii chart  2 
(codes  128 - 255
)。
全角字符的第一个字节总是被置为163,
 而第二个字节则是相同半角字符码加上128(不包括空格)。
 如半角a为65,则全角a则是163(第一个字节)、
193 (第二个字节, 128 + 65 )。
 而对于中文来讲,它的第一个字节被置为大于163,(
 如 ' 阿 ' 为:
176   162 ),我们可以在检测到中文时不进行转换。
}
begin
  nlength: =
length(s);
   if  (nlength = 0 ) then
   
exit;
  str: = '' ;
  setlength(ctmp,nlength + 1 );
 
ctmp: = s;
  i: = 1 ;
   while  (i # 163 ) then   //
如果是汉字
     begin
      str:
= str + c1;
      str: = str +
c2;
      inc(i, 2
);
       continue ;
   
end;
     if  (c1 = # 161 ) and (c2 = # 161 )
then   // 如果是全角空格
    
begin
      str: = str + '   '
;
      inc(i, 2
);
       continue ;
    end;

    str: = str + c1;
    inc(i);
 
end;
  result: = str;
end; ---
本文章使用“国华软件”出品的博客内容离线管理软件MultiBlogWriter撰写并发布


相关文档:

delphi中的DBGRid鼠标滚动事件

Procedure OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
begin
  if Msg.message = WM_MouseWheel then
  begin
    if Msg.wParam > 0 then
     begin
       if DBGrid.Focused then
       ......

VC中调用Delphi的DLL中的回调函数例子

//Delphi部分  
 //回调函数定义
type TOnMyCallBack = procedure(data:pchar; id:Integer);stdcall;  
 //DLL中的导出函数声明
procedure StartCall(param:   TOnMyCallBack(data:pchar; id:Integer);stdcall;  
begin
  ...  
  ...  
end;  
&n ......

delphi中关于字符串数组的一个小BUG

看如下代码:
var
   buffer:array [0..6] of char;
begin
    buffer:='delphi';
end;
编译通过
再看如下代码:
var
   buffer:array [1..7] of char;
begin
    buffer:='delphi';
end;
编译错误:
Incompatible types: 'Array' and 'String'
真不知道 ......

Delphi 关键字

absolute
//它使得你能够创建一个新变量, 并且该变量的起始地址与另一个变量相同.
var
  Str: string[32];
  StrLen: Byte absolute Str;
//这个声明指定了变量StrLen起始地址与Str相同.
//由于字符串的第0个位置保存了字符串的长度, 所以StrLen的值即字符串长度.
begin
  Str := 'abc';
  Ed ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号