作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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/
我在 Windows 7 上使用 Delphi 2010,在递归搜索目录时遇到单引号加倍的问题。 这是我搜索目录的代码。 if FindFirst(aPath + '*', faDirectory
我是一名优秀的程序员,十分优秀!