mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 07:23:28 +08:00
fix: coding style and file format.
This commit is contained in:
@@ -8,12 +8,13 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
// count number of characters:
|
// count number of characters:
|
||||||
str1 := "asSASA ddd dsjkdsjs dk"
|
str1 := "asSASA ddd dsjkdsjs dk"
|
||||||
fmt.Printf("The number of bytes in string str1 is %d\n",len(str1))
|
fmt.Printf("The number of bytes in string str1 is %d\n", len(str1))
|
||||||
fmt.Printf("The number of characters in string str1 is %d\n",utf8.RuneCountInString(str1))
|
fmt.Printf("The number of characters in string str1 is %d\n", utf8.RuneCountInString(str1))
|
||||||
str2 := "asSASA ddd dsjkdsjsこん dk"
|
str2 := "asSASA ddd dsjkdsjsこん dk"
|
||||||
fmt.Printf("The number of bytes in string str2 is %d\n",len(str2))
|
fmt.Printf("The number of bytes in string str2 is %d\n", len(str2))
|
||||||
fmt.Printf("The number of characters in string str2 is %d",utf8.RuneCountInString(str2))
|
fmt.Printf("The number of characters in string str2 is %d", utf8.RuneCountInString(str2))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Output:
|
/* Output:
|
||||||
The number of bytes in string str1 is 22
|
The number of bytes in string str1 is 22
|
||||||
The number of characters in string str1 is 22
|
The number of characters in string str1 is 22
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var a string // global scope
|
var a string // global scope
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a = "G"
|
a = "G"
|
||||||
@@ -8,11 +8,12 @@ func main() {
|
|||||||
f1()
|
f1()
|
||||||
}
|
}
|
||||||
func f1() {
|
func f1() {
|
||||||
a := "O" // new local variable a, only scoped within f1() !
|
a := "O" // new local variable a, only scoped within f1() !
|
||||||
print(a)
|
print(a)
|
||||||
f2()
|
f2()
|
||||||
}
|
}
|
||||||
func f2() {
|
func f2() {
|
||||||
print(a) // global variable is taken
|
print(a) // global variable is taken
|
||||||
}
|
}
|
||||||
|
|
||||||
// GOG
|
// GOG
|
@@ -16,4 +16,5 @@ func m() {
|
|||||||
a = "O" // simple assignment: global a gets a new value
|
a = "O" // simple assignment: global a gets a new value
|
||||||
print(a)
|
print(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GOO
|
// GOO
|
@@ -1,6 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
var a = "G" // global (package) scope
|
var a = "G" // global (package) scope
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
n()
|
n()
|
||||||
@@ -11,7 +11,8 @@ func n() {
|
|||||||
print(a)
|
print(a)
|
||||||
}
|
}
|
||||||
func m() {
|
func m() {
|
||||||
a := "O" // new local variable a is declared
|
a := "O" // new local variable a is declared
|
||||||
print(a)
|
print(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GOG
|
// GOG
|
Reference in New Issue
Block a user