Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Empty-string/Go/empty-string-1.go
Normal file
14
Task/Empty-string/Go/empty-string-1.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// define and initialize an empty string
|
||||
var s string
|
||||
s2 := ""
|
||||
|
||||
// assign an empty string to a variable
|
||||
s = ""
|
||||
|
||||
// check that a string is empty, any of:
|
||||
s == ""
|
||||
len(s) == 0
|
||||
|
||||
// check that a string is not empty, any of:
|
||||
s != ""
|
||||
len(s) != 0 // or > 0
|
||||
23
Task/Empty-string/Go/empty-string-2.go
Normal file
23
Task/Empty-string/Go/empty-string-2.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func test(s string) {
|
||||
if len(s) == 0 {
|
||||
fmt.Println("empty")
|
||||
} else {
|
||||
fmt.Println("not empty")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// assign an empty string to a variable.
|
||||
str1 := ""
|
||||
str2 := " "
|
||||
// check if a string is empty.
|
||||
test(str1) // prt empty
|
||||
// check that a string is not empty.
|
||||
test(str2) // prt not empty
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue