Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Created October 23, 2013 12:15
Show Gist options
  • Save dannguyen/7117543 to your computer and use it in GitHub Desktop.
Save dannguyen/7117543 to your computer and use it in GitHub Desktop.
funny string cleaning
class String
def astrip
self.gsub(/([\302|\240|\s|\n|\t])|(\ ?){1,}/, ' ').gsub("\240",' ').ostrip
end
def clean_chars
self.clean_dashes.clean_funny_spaces
end
def clean_dashes
self.gsub('‐', '-')
end
def clean_funny_spaces
self.gsub(/^[\302\240|\s]*|[\302\240|\s]*$/, '')
end
def ostrip
self.strip.gsub(/^[\302\240|\s]*|[\302\240|\s]*$/, '').gsub(/[\r\n]/, " ")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment