From 1657b9531d0a8f9bcc79487d326b7ad2be43d93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20G=C3=B6r?= Date: Tue, 19 Mar 2024 16:58:12 +0300 Subject: [PATCH] String explained 2 --- main.go | 1 + string_functions/demo2.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 string_functions/demo2.go 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