Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/csv"
- "fmt"
- "os"
- "strings"
- )
- func main() {
- file, err := os.Open("words.csv")
- if err != nil {
- fmt.Println("Ошибка при открытии файла:", err)
- return
- }
- defer file.Close()
- reader := csv.NewReader(file)
- records, err := reader.ReadAll()
- if err != nil {
- fmt.Println("Ошибка при чтении файла CSV:", err)
- return
- }
- columns := records[0]
- words := make([]map[string]string, 0)
- for _, row := range records[1:] {
- word := make(map[string]string)
- for i, col := range columns {
- word[col] = strings.TrimSpace(row[i])
- }
- words = append(words, word)
- }
- languages := []string{"isv", "en", "ru", "be", "uk", "pl", "cs", "sk", "bg", "mk", "sr", "hr", "sl"}
- fmt.Printf("Izberite jezyk %v\n", languages)
- var lang string
- fmt.Scanln(&lang)
- for {
- fmt.Println("Napišite slovo")
- var word string
- fmt.Scanln(&word)
- result := make([]map[string]string, 0)
- for _, w := range words {
- if wordExistsInSplit(word, w[lang]) {
- result = append(result, w)
- }
- }
- if len(result) == 0 {
- fmt.Println("Nema rezultatov")
- continue
- }
- for _, r := range result {
- for _, lang := range languages {
- fmt.Printf("%s %s\n", lang, r[lang])
- }
- fmt.Println()
- }
- }
- }
- func wordExistsInSplit(s string, text string) bool {
- splits := strings.Split(text, ", ")
- for _, split := range splits {
- if split == s {
- return true
- }
- }
- splits = strings.Split(text, "; ")
- for _, split := range splits {
- if split == s {
- return true
- }
- }
- return false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement