delphi中如何判断字符为汉字、英文字母或数字?问题解决即送50分!
解决方案 »
- 我的抉择啊,是否要参加专升本考试,希望大家给我点帮助!
- 关于窗体初始化问题:请大伙想想办法啊!谢谢!
- 求助!
- 为什么我的程序在运行过程中会突然找不到打印机?(QuickReport),在线等待!!!急急
- 如何浮点数格式化为 11,111,111.11格式啊?
- 救命啦 frame 如何同时显示 多个国家文字呀
- delphi调用C的dll但没有返回值,不知道错在哪里了
- isapi+CreateOleObject 不是小瞧人,csdn上的人解决不了这个问题,中低水平免进
- 我快晕死了,这么一个简单的问题。问了2天也没人说明白清楚。是不是太简单不想帮忙啊。成功的话我50分相送!!!
- TDBLabel控件的Caption属性改变时,会触发哪个事件?
- 使用FB 或者 interbase的高手看一下 100分求助
- 怎样从dbgrid中取得具体的某行某列的数据?????
这是判断数字和英文
function GBtoBIG5(value: string): string;
function BIG5toGB(value: string): string;implementationvar BIG5Order : array[0..14757] of Word;
GBOrder : array[0..8177] of Word;function GBOffset(value: string): integer;
begin
if length(value)>=2 then
Result:=(Ord(value[1])-161)*94+(Ord(value[2])-161)
else
Result:=-1;
end;function BIG5Offset(value: string): integer;
begin
if length(value)>=2 then
begin
if (Ord(value[2])>=64) and (Ord(value[2])<=126) then
Result:=(Ord(value[1])-161)*157+(Ord(value[2])-64);
if (Ord(value[2])>=161) and (Ord(value[2])<=254) then
Result:=(Ord(value[1])-161)*157+63+(Ord(value[2])-161);
end
else
Result:=-1;
end;function WordToString(value: Word): string;
begin
Result:=Chr(Hi(value))+Chr(Lo(Value));
end;function isBIG5(value: string): Boolean;
begin
if (length(value)>=2) then
begin
if (value[1]<#161) then
Result:=false
else
if ((value[2]>=#64) and (value[2]<=#126)) or ((value[2]>=#161) and (value[2]<=#254)) then
Result:=true
else
Result:=false;
end
else
Result:=false;
end;function isGB(value: string): Boolean;
begin
if (length(value)>=2) then
begin
if (value[1]<=#161) and (value[1]>=#247) then
Result:=false
else
if (value[2]<=#161) and (value[2]>=#254) then
Result:= false
else
Result:=true;
end
else
Result:=true;
end;function GBtoBIG5(value: string): string;
var leng, idx : integer;
tmpStr : string[2];
Offset : integer;
output : string;
begin
output:='';
leng:=length(value);
idx:=1;
while idx<=leng do
begin
tmpStr:=value[idx]+value[idx+1];
if isGB(tmpStr) then
begin
offset:=GBOffset(tmpStr);
if (offset>=0) and (offset<=8177) then
begin
output:=output+WordToString(GBOrder[offset]);
inc(idx);
end
else
output:=output+value[idx] ;
end
else
output:=output+value[idx] ; inc(idx,1);
end;
Result:=output;
end;function BIG5toGB(value: string): string;
var leng,idx : integer;
tmpStr : string[2];
output : string;
offset : integer;
begin
output:='';
leng:=length(value);
idx:=1;
while idx<=leng do
begin
tmpStr:=value[idx]+value[idx+1];
if isBIG5(tmpStr) then
begin
offset:=BIG5Offset(tmpStr);
if (offset>=0) and (offset<=14757) then
begin
output:=output+WordToString(BIG5Order[offset]);
inc(idx);
end
else
output:=output+value[idx];
end
else
output:=output+value[idx]; inc(idx);
end;
Result:=output;
end; 大富翁裡面找的
It is Far East Language includes chinese
var
str:string;
I:Integer;
begin
str:='Ads6f.,你好2';
I:=1;
while I<=Length(str) do
begin
if Integer(str[I])>$a0 then
begin
ShowMessage('汉字');
Inc(I);
end
else if str[I] in ['0'..'9'] then
ShowMessage('数字')
else if str[I] in ['a'..'z','A'..'Z'] then
ShowMessage('字母')
else ShowMessage('非法字符');
Inc(I);
end;
end;
可以这样判断,具体你要怎么弄自己写过
if char in ['0'..'9'] then
//数字
if char in ['A'..'Z','a'..'z'] then
//字母
if ord(char)>255 then
inc(i);
{i/2就是汉字,这个办法很简陋..}
Or (ByteType(copy(StrTemp, 1, 24), 24) = mbTrailByte) Then
Begin //单字母 //双字节中第二位 //直接打印
Printer.Canvas.TextOut(pstX_Bank, pstY_Bank +
(i - 1) * h + 1, copy(StrTemp, 1, 24));
StrTemp:= copy(StrTemp, 25, Length(StrTemp) - 24);
End
Else
If ByteType(copy(StrTemp, 1, 24), 24) = mbLeadByte Then //双字节中第一位
Begin //留下一行打印
Printer.Canvas.TextOut(pstX_Bank, pstY_Bank +
(i - 1) * h + 1, copy(StrTemp, 1, 23));
StrTemp:= copy(StrTemp, 24, Length(StrTemp) - 23);
End;这是我自己的程序中用的一段代码,看看能不能帮上你的忙,其实就是用ByteType判断字符是什么,是单个字符还是汉字的后一位,就可以知道是单字符的数字,字母,还是双字节汉字了
'0'..'9':
showmessage('数字');
'a'..'z','A'..'Z':
showmessage('英文');
else
showmessage('汉字');
end;