I can't remove whitespaces from a string parsed by Nokogiri

前端 未结 2 1627
有刺的猬
有刺的猬 2021-02-09 06:34

I can\'t remove whitespaces from a string.

My HTML is:

Cena pro Vás: 139 

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-09 07:15

    strip only removes ASCII whitespace and the character you've got here is a Unicode non-breaking space.

    Removing the character is easy. You can use gsub by providing a regex with the character code:

    gsub(/\u00a0/, '')
    

    You could also call

    gsub(/[[:space:]]/, '')
    

    to remove all Unicode whitespace. For details, check the Regexp documentation.

提交回复
热议问题