我尝试删除字符串开头的非字母字符,但是当字符串中只有非字母字符(如“!!”或“?!?”)时,它会产生访问冲突错误。以下是我的代码:
这是我的日志生成的内容:
// The Log(); is a routine that adds stuff to my log memo.
Log('Begin Parse');
while not IsLetter(ParsedName[1]) do
begin
Log('Checking Length - Length is '+IntToStr(Length(ParsedName))+' ...');
if Length(ParsedName) <> 0 then
Begin
Log('Deleting Char ...');
Delete(ParsedName,1,1);
Log('Deleted Char ...');
End;
Log('Checking Length - Length is now '+IntToStr(Length(ParsedName))+' ...');
end;
// It never reaches this point!
Log('End Parse');
这是我的日志生成的内容:
21:51:19: Checking Length - Length is 2 ...
21:51:19: Deleting Char ...
21:51:19: Deleted Char ...
21:51:19: Checking Length - Length is now 1 ...
21:51:19: Checking Length - Length is 1 ...
21:51:19: Deleting Char ...
21:51:19: Deleted Char ...
21:51:19: Checking Length - Length is now 0 ...
21:51:19: Access violation at address 007A1C09 in module 'Project1.exe'. Read of address 00000000
如您所见,这是在所有字符都被删除后发生的。我猜问题在于我试图访问不存在的东西,但是我不知道我是怎么做到的。
编辑:是的,我知道这是一个愚蠢的问题和所有那些东西 - 我只是忽略了一些细节。别告诉我你从来没有过这种情况 ;)