Method: String#clean_string
- Defined in:
- lib/boris/core_ext/string.rb
#clean_string ⇒ String
Cleans self by stripping leading/trailing spaces, any consecutive spaces, and removing any ASCII characters that are sometimes reported by devices. Also removes registered ® characters.
'Microsoft(R) Windows(R)'.clean_string #=> "Microsoft Windows"
"string with\u00A0 weird character".clean_string #=> "string with weird character"
118 119 120 121 122 123 124 |
# File 'lib/boris/core_ext/string.rb', line 118 def clean_string # remove registered "(R)" and trademark "(tm)" marks string = self.gsub(/\(r\)|\(tm\)/i, '') string.gsub!(/\s+/, ' ') string.encode(Encoding.find('ASCII'), :undef=>:replace, :replace=>'').strip end |