String explained 2
This commit is contained in:
parent
d1fbf4865b
commit
1657b9531d
2 changed files with 33 additions and 0 deletions
1
main.go
1
main.go
|
@ -127,4 +127,5 @@ func main() {
|
||||||
error_handling.Demo2()
|
error_handling.Demo2()
|
||||||
fmt.Println(error_handling.GuessIt2(102))
|
fmt.Println(error_handling.GuessIt2(102))
|
||||||
string_functions.Demo1()
|
string_functions.Demo1()
|
||||||
|
string_functions.Demo2()
|
||||||
}
|
}
|
||||||
|
|
32
string_functions/demo2.go
Normal file
32
string_functions/demo2.go
Normal 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))
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue