String explained 2

This commit is contained in:
Mert Gör ☭ 2024-03-19 16:58:12 +03:00
parent d1fbf4865b
commit 1657b9531d
Signed by: hwpplayer1
GPG Key ID: 03E547D043AB6C8F
2 changed files with 33 additions and 0 deletions

View File

@ -127,4 +127,5 @@ func main() {
error_handling.Demo2()
fmt.Println(error_handling.GuessIt2(102))
string_functions.Demo1()
string_functions.Demo2()
}

32
string_functions/demo2.go Normal file
View File

@ -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))
}