帮我看一条代码,谢谢(50分)

  • 主题发起人 主题发起人 leo_anyu
  • 开始时间 开始时间
L

leo_anyu

Unregistered / Unconfirmed
GUEST, unregistred user!
while (hang[fir]<>str) and (hang[fir]=' ') do
hang是一个string类型fir:=0
 
string类型从1开始访问。
另,应该判断一下是否到字符串结尾了。
fir <= Length(hang)
 
那就是说判定条件的写法没有问题,可是,str和hang[fir]中的有好多不同字符且hang[fir]中也有好多两个连续空格,为什么不执行循环呢?(我已经把fir的初始改成1了)
 
"可是,str和hang[fir]中的有好多不同字符且hang[fir]中也有好多两个连续空格,为什么不执行循环呢?"
while (hang[fir]<>str) and (hang[fir]=' ') do
这个语句从第一个hang[fir] 不是空格就退出循环了
改成 while (hang[fir]<>str) or (hang[fir]=' ') do
 
str:string;
setlength(str,10);
为什么要加setlength?不加会出现错误
 
setlength(str,10);
setlength(hang,400);
str:=rzEdit1.Text;
for i:=0 to strList1.Count-1 do
begin
fir:=1;
beh:=1;
hang:=strList1;
rzEdit2.Text:=intToStr(length(hang));
if pos(str,hang)>0 then
begin
while (hang[beh]<>str)do
begin
if beh<=Length(hang) then
begin
if (hang[beh]=' ') then//等号右写一个空格就识别,写两个空格就不行
//,因为我的文本里面都是两个空格的
//现在写一个空格可以执行(#32也可以)
begin
left1:=copy(hang,fir,beh);
rzListBox1.Items.Add(left1);
fir:=beh;
end;
end;
inc(beh);
end;

end;
end;
程序可以执行
不过此程序执行到最后又会出现问题
 
出现异常:project StrPro.exe raised exception calss EAccessViolation with
message'Access violation at address 00481516 in module'StrPro.exe'.Read of address 00DB8000'.Process stopped.Use Step or Run to continue.
 
hehe,找到答案了
 
hand应该是一个字符串数组。
 
多人接受答案了。
 
后退
顶部