简体   繁体   中英

Removing a character from string in Rspec

I am new to Rspec and I am facing a little issue.

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. Can anybody help on this?

您可以使用String#sub替换它:

'15%'.sub('%', '') #=> '15'

如果出现多个事件,也可以使用gsub:

'15%%%'.gsub('%', '') #=> '15'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM