di linux (saya pakai centos):
Last active
August 30, 2018 08:28
-
-
Save birowo/b74133bfa9b503781247c04f01a10615 to your computer and use it in GitHub Desktop.
golang: membaca inputan user di terminal / stdin
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
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
println("inputkan beberapa baris data, akhiri dengan Ctrl-Z lalu Enter") | |
result, _ := ioutil.ReadAll(os.Stdin) | |
newLine := []byte("\r\n") | |
println("cetak hasil :") | |
println(string(bytes.Replace(result, newLine, []byte(", "), -1))) | |
println("pecah hasil perbaris :") | |
//jika diinginkan inputan perbaris tinggal split result with separator \r\n | |
fmt.Printf("%q\n", bytes.Split(result, newLine)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment