删除所有空格的Ruby函数? [英] Ruby function to remove all white spaces?

查看:27
本文介绍了删除所有空格的Ruby函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

删除所有空格的 Ruby 函数是什么?我正在寻找类似于 PHP 的 trim()?

What is the Ruby function to remove all white spaces? I'm looking for something kind of like PHP's trim()?

推荐答案

如果您只想删除前导和尾随空格(如 PHP 的修剪),您可以使用 .strip,但如果您想删除所有空格,您可以使用 .gsub(/\s+/, "") 代替.

If you want to remove only leading and trailing whitespace (like PHP's trim) you can use .strip, but if you want to remove all whitespace, you can use .gsub(/\s+/, "") instead .

这篇关于删除所有空格的Ruby函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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