将字符串变成仅1行 [英] Make String into only 1 line

查看:100
本文介绍了将字符串变成仅1行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的输出基本上是一个段落,当我尝试在字符串中搜索一个子字符串时,如果该子字符串被拆分,它将不起作用。如何将段落字符串变成仅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 doesnt' work. How can I make the paragraph string into just 1 line?

示例字符串:

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。

When I try to search for that substring, it doesn't return true.

推荐答案

似乎您想将换行符视为空格。编写高效的搜索算法并非易事,但可行并回答标题中的问题的方法是

It seems like you want to treat newlines as spaces. Writing efficient search algorithms is not trivial, but an approach that works and answers the question in your title, is

str := StringReplace(str, sLineBreak, ' ', [rfReplaceAll]);

也就是说,我们只是将所有换行符替换为空格。没有魔术常数,这是

That is, we simply replace all linebreaks with spaces. Without the magic constants, this is

str := StringReplace(str, #13#10, #32, [rfReplaceAll]);

除了换行符外,单词之间是否已经存在空格?然后只需删除换行符,而不添加空格即可:

Perhaps there are already spaces between the words, in addition to the linebreaks? Then just remove the linebreaks, without adding spaces:

str := StringReplace(str, #13#10, '', [rfReplaceAll]);

这篇关于将字符串变成仅1行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆