while ((IsLetterOrNumber(Gl_ch))=0) or
((IsLetterOrNumber(Gl_ch))=1) do
begin
Inputword:=Inputword+Gl_ch;
showmessage(Gl_ch+' + '+inputword);
str_Input:=GetStringTail(str_Input);
Gl_ch:=ReadChar(str_Input);
end;---------------------------------------
说明:
function IsLetterOrNumber(ch:Char):integer;
begin
if ((ch>='a') and (ch<='z')) or ((ch>='A') and (ch<='Z')) then Result:=0 //字母
else if (ch>='0') and (ch<='9') then Result:=1//数字
else if (ch=' ') then Result:=3//空格
else Result:=2; //其他
end;
function GetStringTail(Str:String):string;
var
str_temp:string;
int_Strlength:integer;
begin
int_strlength:=length(Trim(str));
str_temp:=copy(str,2,int_strlength);
result:=str_temp;
end;function ReadChar(str:String):char;
begin
if Length(str)>0 then Result:=str[1]
end;
((IsLetterOrNumber(Gl_ch))=1) do
begin
Inputword:=Inputword+Gl_ch;
showmessage(Gl_ch+' + '+inputword);
str_Input:=GetStringTail(str_Input);
Gl_ch:=ReadChar(str_Input);
end;---------------------------------------
说明:
function IsLetterOrNumber(ch:Char):integer;
begin
if ((ch>='a') and (ch<='z')) or ((ch>='A') and (ch<='Z')) then Result:=0 //字母
else if (ch>='0') and (ch<='9') then Result:=1//数字
else if (ch=' ') then Result:=3//空格
else Result:=2; //其他
end;
function GetStringTail(Str:String):string;
var
str_temp:string;
int_Strlength:integer;
begin
int_strlength:=length(Trim(str));
str_temp:=copy(str,2,int_strlength);
result:=str_temp;
end;function ReadChar(str:String):char;
begin
if Length(str)>0 then Result:=str[1]
end;
执行Gl_ch:=ReadChar(str_Input)后, Gl_ch总是为"H"。这样,在进行while判断时,自然总是不能跳出。那么为什么Gl_ch到最后总是为H呢?
不明白啊!
要怎么解决呢?
Gl_ch:=ReadChar(str_Input)
showmessage(Gl_ch);
到最后显示的总是H
Gl_ch:=ReadChar(str_Input);
你的STR——INPUT不变,当然GL——CH也不变了;
function GetStringTail(Str:String):string;
var
str_temp:string;
int_Strlength:integer;
begin
int_strlength:=length(Trim(str));
str_temp:=copy(str,2,int_strlength); //就在这里!减少了第一个字符!
result:=str_temp;
end;
修改为:
Result:='';
if Length(str)>0 then Result:=str[1];
现在才发现一个问题!
为什么现在在CSDN上我找不到提问的地方了?
---->str_temp := RightStr(str, int_strlength-1)
Result:=''不行吧,类型不匹配
begin
if Length(str)>0 then
Result:=str[1]
else
Result := #0
end;
把分给了westfly(西翔)吧,其实跟踪一下就会发现
length为0
Gl_ch值为str最后一个,没法改变
你的ReadChar调用也有问题
begin
j:=IsLetterOrNumber(str_Input[i])
if (j=0) or (j=1) then
BEGIN
Gl_ch:=ReadChar(str_Input); Inputword:=Inputword+Gl_ch;
END
ELSE
BREAK;
end;
效率高多了
while ((IsLetterOrNumber(Gl_ch))=0) or
((IsLetterOrNumber(Gl_ch))=1) do
begin
Inputword:=Inputword+Gl_ch;
showmessage(Gl_ch+' + '+inputword);
str_Input:=GetStringTail(str_Input);
Gl_ch:=ReadChar(str_Input);
end;
修改为:
Result:=Char(0);
if Length(str)>0 then Result:=str[1];