如何替换perl中的空格 [英] How to Replace white space in perl

查看:70
本文介绍了如何替换perl中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

chomp($myString);
$myString =~ s/\///g;

我可以用

$myString =~ s/\s//g;

有什么区别吗?请解释.

are there any difference? Please explain.

推荐答案

如果 $myString 存在,您的第一个代码将从 $myString 的末尾删除一个换行符,然后删除所有 "/" 字符.第二行代码将删除所有空白字符.有错别字吗?

Your first code will take a newline off the end of $myString if it exists and then remove all "/" characters. The second line of code will remove all whitespace characters. Is there a typo?

也许你想知道你可以替换这个:

Maybe you want to know you can replace this:

chomp($myString);
$myString =~ s/\s//g;

这样:

$myString =~ s/\s//g;

如果这是问题,那么是的.由于换行符算作空格,第二个代码示例完成了上面两行的工作.

If that's the question, then yes. Since a newline counts as whitespace, the second code example do the job of both lines above.

这篇关于如何替换perl中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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