[英]Removing a character from string in Rspec
I am new to Rspec and I am facing a little issue. 我是Rspec的新手,现在面临一个小问题。
text = page.find(:xpath,"some xpath").text
the code line above gets the value from a html element ie 15% or any other value under 100, I want to remove % sign from the value after and getting it to use for comparison. 上面的代码行从html元素获取值,即15%或100以下的任何其他值,我想从该值后删除%符号,然后将其用于比较。 Can anybody help on this?
有人可以帮忙吗?
您可以使用String#sub
替换它:
'15%'.sub('%', '') #=> '15'
如果出现多个事件,也可以使用gsub:
'15%%%'.gsub('%', '') #=> '15'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.