package main
import "fmt"
//compare strings function
func main() {
fmt.Println(compare("yes", "yoo"));
}
func compare(x, y string) bool{
if (len(x) == len(y)) {
for i := 0;i<len(x);i++ {
if(x[i] != y[i]) {
return false
}
}
return true
} else {
return false
}
}
golang go中的字符串转换示例
package main
import "fmt"
//wraps a value in any type
func value(elem interface{}) interface{} {
return elem
}
func str(elem interface{}) string {
return elem.(string)
}
func main() {
fmt.Println(value("hello world"))
fmt.Println(value("hello world").(string) + " This is a string cast")
fmt.Println(str(value("hello word")) + " this is another cast")
}