gpt4 book ai didi

Delphi 在使用 FindFirst/FindeNext 搜索时将单引号加倍

转载 作者:行者123 更新时间:2023-12-03 06:54:09 24 4
gpt4 key购买 nike

我在 Windows 7 上使用 Delphi 2010,在递归搜索目录时遇到单引号加倍的问题。

这是我搜索目录的代码。

  if FindFirst(aPath + '*', faDirectory, sr) = 0 then
try
repeat
if (sr.Name <> '.') and (sr.Name <> '..') then
if (sr.Attr and faDirectory) = faDirectory then
SearchFolderEx(aPath + sr.Name + '\', aSearchMasks);

until FindNext(sr) <> 0;
finally
FindClose(sr);
end;

现在有了这样的路径(从“C:\New folder\”开始)

C:\New folder\New Folder's\New Text Document.txt

FindFirst/FindeNext 加倍单引号

'New Folder''s'

来自 TSearchRec 的 FindData.cFileName 看起来像这样

('N', 'e', 'w', ' ', 'F', 'o', 'l', 'd', 'e', 'r', '''', 's', #0, #0, ...)

问题出在哪里,我该如何解决?

最佳答案

这里没有问题,没有什么需要修复的。 ' 是字符串定界符,简单地转义以表示为 ''。当调试器在字符串中向您显示 '' 时,这只是它表示单引号字符的方式。

文档在此处涵盖此主题:Character Strings .

所以,

''''

是一个长度为1的字符串,其单个元素是引号。

同样

'New Folder''s'

是定义字符串的Delphi字符串文字

New Folder's

调试器使用与字符串文字相同的规则向您显示变量的内容。

关于Delphi 在使用 FindFirst/FindeNext 搜索时将单引号加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10987364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com