diff --git a/main.go b/main.go index 4433889..6315cef 100644 --- a/main.go +++ b/main.go @@ -127,4 +127,5 @@ func main() { error_handling.Demo2() fmt.Println(error_handling.GuessIt2(102)) string_functions.Demo1() + string_functions.Demo2() } diff --git a/string_functions/demo2.go b/string_functions/demo2.go new file mode 100644 index 0000000..8404969 --- /dev/null +++ b/string_functions/demo2.go @@ -0,0 +1,32 @@ +package string_functions + +//alias +import ( + + "fmt" + + s "strings" +) + +func Demo2() { + name := "Engin" + fmt.Println(s.HasPrefix(name, "Eng")) // true + fmt.Println(s.HasSuffix(name, "in")) // true + fmt.Println(s.Index(name, "in")) // index starts from 0 / zero + + letters := []string{"e", "n", "g","i","n"} + fmt.Println(s.Join(letters, "*")) + result := s.Join(letters, "*") + fmt.Println(result) + + fmt.Println(s.Replace(result, "*", "+", -1)) + fmt.Println(s.Replace(result, "*", "+", 3)) + + // For banking : ID Number : 123123121, Date: 02022021, Amount : 5999 + + fmt.Println(s.Split(result, "*")) + fmt.Println(len(s.Split(result, "*"))) + fmt.Println(s.Split(result, "-")) + fmt.Println(s.Repeat(result, 5)) + +} \ No newline at end of file