-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.go
70 lines (50 loc) · 1.35 KB
/
string.go
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
66
67
68
69
70
// Go program to illustrate
// how to trim a string
package main
import (
"fmt"
"strings"
)
// Main method
func main() {
// Creating and initializing string
// Using shorthand declaration
str1 := "!!Welcome to GeeksforGeeks !!"
str2 := "@@This is the tutorial of Golang$$"
// Displaying strings
fmt.Println("Strings before trimming:")
fmt.Println("String 1: ", str1)
fmt.Println("String 2:", str2)
// Trimming the given strings
// Using Trim() function
res1 := strings.TrimSpace(str1)
res2 := strings.Trim(str2, "@$")
trimmed := strings.Join(strings.Fields(str1), " ")
// Displaying the results
fmt.Println("\nStrings after trimming:")
fmt.Println("Result 1: ", res1)
fmt.Println("Result 2:", res2)
fmt.Println("trimmed 2:", trimmed)
y := 458
// taking a pointer variable using
// := by assigning it with the
// address of variable y
p := &y
fmt.Println()
fmt.Println("Value stored in y = ", y)
fmt.Println("Address of y = ", &y)
fmt.Println("Value stored in pointer variable p = ", p)
fmt.Println()
fmt.Println("Value stored in y(*p) = ", *p)
*p = 500
fmt.Println("Value stored in y(*p) after Changing = ", y)
fmt.Println()
var x = 100
fmt.Printf("The value of x before function call is: %d\n", x)
var pa *int = &x
ptf(pa)
fmt.Printf("The value of x after function call is: %d\n", x)
}
func ptf(a *int) {
*a = 7480
}