Learning GO
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
module main
|
||||
|
||||
go 1.26.5
|
||||
@@ -0,0 +1 @@
|
||||
There was a kid named Sami, and his sister Leena.
|
||||
@@ -0,0 +1 @@
|
||||
There was a kid named Sami, and his sister Girl.
|
||||
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// s := "élite"
|
||||
//
|
||||
// fmt.Printf("%8T %[1]v %d\n", s, len(s))
|
||||
// r := []rune(s)
|
||||
// fmt.Printf("%8T %[1]v %d\n", r, len(r))
|
||||
// b := []byte(s)
|
||||
// fmt.Printf("%8T %[1]v %d\n", b, len(b))
|
||||
|
||||
// s := "The Quick brown fox"
|
||||
//
|
||||
// length := len(s)
|
||||
//
|
||||
// b := s[:3]
|
||||
// c := s[3:9]
|
||||
// d := s[:4] + "Fast" + s[9:]
|
||||
//
|
||||
// s += "es"
|
||||
//
|
||||
// fmt.Println(length)
|
||||
// fmt.Println(b)
|
||||
// fmt.Println(c)
|
||||
// fmt.Println(d)
|
||||
// fmt.Println(s)
|
||||
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Fprintln(os.Stderr, "Not enough args")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
old, replacemnt := os.Args[1], os.Args[2]
|
||||
scan := bufio.NewScanner(os.Stdin)
|
||||
|
||||
for scan.Scan() {
|
||||
s := strings.Split(scan.Text(), old)
|
||||
t := strings.Join(s, replacemnt)
|
||||
|
||||
fmt.Println(t)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user