Last active
August 17, 2019 10:06
-
-
Save quyen91/769daa1be2c28dd59925b27ef0df6894 to your computer and use it in GitHub Desktop.
Remove vietnamese accent ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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