如何删除Perl中的所有空格和换行符?

时间:2010-10-14 08:54:26

标签: perl

我有一个看起来像这样的字符串......

  


  http://www.example.com/

     

为例.pdf“

我需要删除空格和换行符。我该怎么做呢?我的结果应该是

"http://www.example.com/example.pdf"

2 个答案:

答案 0 :(得分:19)

只需使用s///替换运算符:

$string =~ s/\s+//g;

\s character class匹配空格字符集[\ \t\r\n\f]和其他字符。

答案 1 :(得分:0)

while (<>) { s/\s+//g; print; }

相关问题