如何删除 Ruby 中的不间断空格 [英] How do I remove a non-breaking space in Ruby

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

问题描述

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

I have a string that looks like this:

d = "foo\u00A0\bar"

当我检查长度时,它说它是 7 个字符长.我在网上查了一下,发现这是一个不间断的空间.有人可以告诉我如何删除字符串中的所有不间断空格吗?

When I check the length, it says that it is 7 characters long. I checked online and found out that it is a non-breaking space. Could someone show me how to remove all the non-breaking spaces in a string?

推荐答案

irb(main):001:0> d = "foo\u00A0\bar"
=> "foo \bar"
irb(main):002:0> d.gsub("\u00A0", "")
=> "foo\bar"

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

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