我的输出基本上是一个段落,当我尝试在字符串中搜索子字符串时,如果该子字符串被拆分,则它不起作用。如何使段落字符串只有 1 行?
示例字符串:
I have an output that is basically a paragraph and when I try
to search the string for a substring, if that substring is split up it
doesn't work. How can I make the paragraph string into just 1 line?
子字符串:“它不起作用”
当我尝试搜索该子字符串时,它不会返回 true。
最佳答案
您似乎想将换行符视为空格。编写高效的搜索算法并非易事,但有效并回答标题中问题的方法是
str := StringReplace(str, sLineBreak, ' ', [rfReplaceAll]);
也就是说,我们只需用空格替换所有换行符。没有魔法常数,这就是
str := StringReplace(str, #13#10, #32, [rfReplaceAll]);
除了换行符之外,也许单词之间已经有空格了?然后只需删除换行符,而不添加空格:
str := StringReplace(str, #13#10, '', [rfReplaceAll]);
关于string - 将 String 变成只有 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6668808/