0

I am trying to remove a registered trademark from the end of a string so I can compare the two string's Levenshtein normalized distance and get an accurate number.

Does anyone know an easy way to strip the registered trademark symbol off the end of a string in Ruby?

For example:

example_name1 = Tylenol®
example_name2 = Tylenoloafjd
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • `mb_chars` might help you: http://apidock.com/rails/String/mb_chars – MrYoshiji Jun 03 '14 at 20:42
  • The whole point is to measure string distance so I am using misspellings as examples to user2864740 – user2916948 Jun 03 '14 at 20:48
  • have you considered a regex to only capture the parts you want e.g. ([A-Za-z]) – user3334690 Jun 03 '14 at 20:49
  • The only problem with that is that the unicode contains a-z chars so I am not sure how to use a regex to get around it since it contains alpha numeric characters user3334690 – user2916948 Jun 03 '14 at 20:50
  • The purpose for Stack Overflow is to help you fix problems in code you've written. Please show us what you've tried, and show why they didn't work. – the Tin Man Jun 03 '14 at 21:40

1 Answers1

0

If you can do such things:

  1. Make sure you're using ruby 2.0 or later.
  2. Make sure your editor is encoding the actual file in UTF-8

And then you can do it just like normal:

example_name1.chomp!("®")
gwcoffey
  • 5,551
  • 1
  • 18
  • 20
  • You don't need the magic `#encoding: UTF-8` comment in Ruby >= 2.0, since UTF-8 is the default encoding there. – DMKE Jun 03 '14 at 21:07
  • Thanks! I didn't realize that. I revised my answer. And I can revise a lot of my code :) – gwcoffey Jun 03 '14 at 21:13
  • Unfortunately, I am working in 1.9.3 so that doesn't appear to work – user2916948 Jun 03 '14 at 21:16
  • I ended up referencing this post and solving the problem http://stackoverflow.com/questions/1268289/how-to-get-rid-of-non-ascii-characters-in-ruby – user2916948 Jun 03 '14 at 21:36