forked from TECHOUS/DSKaKhel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.go
More file actions
65 lines (44 loc) · 1014 Bytes
/
Strings.go
File metadata and controls
65 lines (44 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"strings"
)
func main() {
// string concatenation
s1 := "a black car"
fmt.Println(s1)
s2 := s1 + " and a bycle"
fmt.Println(s2)
fmt.Println()
// comparing two strings
s3 := "Apple"
s4 := "apple"
if s3 == s4 {
fmt.Println("the strings are equal")
} else {
fmt.Println("the strings are not equal")
}
if strings.EqualFold(s3, s4) {
fmt.Println("the strings are equal")
} else {
fmt.Println("the strings are not equal")
}
fmt.Println()
// escape sequence
s5 := "House\tman\nwoman\ta dog\n"
fmt.Println(s5)
s6 := "Have a \"safe flight\""
fmt.Println(s6)
fmt.Println()
// looping strings - using a for loop, it loops the string over bytes
s7 := "Green"
for idx, s := range s7 {
fmt.Printf("The index number of %c is %d\n", s, idx)
}
fmt.Println()
fmt.Println("using Bytes:")
for i := 0; i < len(s7); i++ {
fmt.Printf("%x ", s7[i])
}
fmt.Println()
}