[url=http://stackoverflow.com/questions/1752414/how-to-reverse-a-string-in-go]http://stackoverflow.com/questions/1752414/how-to-reverse-a-string-in-go[/url])
package main
import (
"fmt"
)
func main(){
ForExample()
fmt.Println("----------------------")
GoExample()
fmt.Println("----------------------")
ArrExample()
fmt.Println("----------------------")
Revert("testRevert hah")
}
func ForExample(){
for i:= 0; i < 10; i++ {
fmt.Println(i)
}
}
func GoExample(){
i := 0
I:
fmt.Println(i)
i++
if(i < 10) {
goto I
}
}
func ArrExample(){
arr := [10]int{0,1,2,3,4,5,6,7,8,9}
for _,val := range arr{
fmt.Println(val)
}
}
func Revert(s string){
var result string
for _,val := range s{
result = string(val) + result
}
fmt.Println(result)
}
希望本文所述对大家Go语言程序设计有所帮助。