Skip to content

Instantly share code, notes, and snippets.

@quyen91
Last active August 17, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quyen91/769daa1be2c28dd59925b27ef0df6894 to your computer and use it in GitHub Desktop.
Save quyen91/769daa1be2c28dd59925b27ef0df6894 to your computer and use it in GitHub Desktop.
Remove vietnamese accent ruby
from = "àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịýỷỳỹỵäëïîöüûñç·/_,:;"
to = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiyyyyyaeiiouunc------"
str = "DEMO STRING"
hash = {}
for i in 0..from.length - 1
hash[from[i]] = to[i]
end
str.downcase.gsub(/[àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịýỷỳỹỵäëïîöüûñç·/_,:;]/, hash)
str = str.gsub(/[^a-z0-9 -]/, '') # remove invalid chars
.gsub(/\s+/, '-') # remove white space
.gsub(/-+/, '-')
# inspired by:
https://gist.github.com/bluzky/b8c205c98ff3318907b30c3e0da4bf3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment