1

I have to write a simple program in go which takes some words separated from (,.: /n )and stores these words in a slice, from keyboard or command line or a .txt/xlsx/docx file (one program for each kind of input). Here on SO I have found these solutions:

How to fill a slice with scan values Reading a file line by line in Go How to read/write from/to a file using Go

But I'd like to know if there are some easier/most efficient ways to do this, especially without having to return all these nil values. And I have the same problem with files. What is the most efficient/clean way to do this? Thanks for your help.

Lory
  • 40
  • 9
  • 3
    Just write it the best way you can and see if it's enough, then show us your code if it does not work. What I can recommend is using the `strings.Split` function for this. All you have to do is load input into one string and split it on the separator. – Jakub Dóka Mar 30 '22 at 17:31
  • It's fine, but then what should I do? I thought to use bufio or Fmt.Scan, but I don't know how can I proceed. – Lory Mar 30 '22 at 17:52

0 Answers0