我有一个输出基本上是一个段落,当我尝试搜索字符串的子字符串时,如果该子字符串被拆分它不起作用.如何将段落字符串变成一行?
示例字符串:
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?
Run Code Online (Sandbox Code Playgroud)
子串:"它不起作用"
当我尝试搜索该子字符串时,它不会返回true.
And*_*and 16
您似乎希望将换行视为空格.编写高效的搜索算法并非易事,但是一种可以在标题中起作用并回答问题的方法
str := StringReplace(str, sLineBreak, ' ', [rfReplaceAll]);
Run Code Online (Sandbox Code Playgroud)
也就是说,我们只需用空格替换所有换行符.没有魔法常数,这是
str := StringReplace(str, #13#10, #32, [rfReplaceAll]);
Run Code Online (Sandbox Code Playgroud)
除了换行符之外,这些词之间可能已经有空格了吗?然后只需删除换行符,而不添加空格:
str := StringReplace(str, #13#10, '', [rfReplaceAll]);
Run Code Online (Sandbox Code Playgroud)