Created
April 11, 2022 18:04
-
-
Save xacnio/b742e21cdb4a7676c5ce0d75e26ac398 to your computer and use it in GitHub Desktop.
Golang - Turkish characters to english characters
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
func TurkishToEnglish(text string) string { | |
var text2 = []rune(text) | |
chars := map[rune]rune{ | |
'ğ': 'g', 'Ğ': 'G', 'Ü': 'U', 'ü': 'u', 'ş': 's', 'Ş': 'S', 'Ö': 'O', 'ö': 'o', 'ç': 'c', 'Ç': 'C', 'İ': 'I', 'ı': 'i', | |
} | |
for i := 0; i < len(text2); i++ { | |
if val, ok := chars[text2[i]]; ok { | |
text2[i] = val | |
} | |
} | |
return string(text2) | |
} | |
// Example | |
// text := "Gökkuşağı, Türkçe, İngilizce, Ölüm, Çevik" | |
// newText := TurkishToEnglish(text); | |
// fmt.Println(newText) // Gokkusagi, Turkce, Ingilizce, Olum, Cevik |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment