如何删除或跳过字符串中的多个新行?

Posted

技术标签:

【中文标题】如何删除或跳过字符串中的多个新行?【英文标题】:How to remove or skip the multiple new line in string? 【发布时间】:2020-08-12 19:59:12 【问题描述】:
DECLARE
   v_string VARCHAR2(4000) := 'A database is an organized collection of data, 
   generally stored and accessed electronically 
   from a computer system. Where databases are more
  
  
   
  complex they are often developed 
  using formal design and modeling techniques.';
   v_sql_code_new VARCHAR2(4000);
BEGIN
END;
 /  

  Desired output: 
     A database is an organized collection of data, 
     generally stored and accessed electronically 
     from a computer system. Where databases are more
     complex they are often developed 
     using formal design and modeling techniques.

我正在尝试从字符串中删除所有换行符。我尝试使用 regexp_replace 但无法获得所需的结果。 提前谢谢你

【问题讨论】:

【参考方案1】:

虽然'^\s*$'也可以与modifier=>'mn'一起使用,最简单的方法是替换多个chr(10):

DECLARE
   v_string VARCHAR2(4000) := 'A database is an organized collection of data, 
   generally stored and accessed electronically 
   from a computer system. Where databases are more
  
  
   
  complex they are often developed 
  using formal design and modeling techniques.';
   v_sql_code_new VARCHAR2(4000);
BEGIN
   dbms_output.put_line(regexp_replace(v_string,chr(10)||'(\s*'||chr(10)||')+',chr(10)));
END;
/

\s*这里只是删除只包含空格字符的行。

【讨论】:

以上是关于如何删除或跳过字符串中的多个新行?的主要内容,如果未能解决你的问题,请参考以下文章

C# 压缩文件。如何提取或跳过名称中包含无效字符的文件?

忽略或跳过 Git 上的某些提交 [重复]

modx 1.05 - 如何删除同上通话中的新行

如何从用户控制台输入中删除新行

从 C# 添加新行时如何在 GridView 中添加删除链接?

如何在写新行时删除旧行?