package main
import (
"fmt"
)
func testReverStringv1() {
/*反转英文*/
var (
str = "hello"
bytes []byte = []byte(str)//转换
)
fmt.Println("bytes =",bytes)
for i:=0;i<len(str)/2;i++ {
tmp := bytes[len(str)-i-1]
fmt.Println("bytes[len(str)-i-1]=======",bytes[len(str)-i-1])
fmt.Println("bytes[len(str)-i-1]=======",string(bytes[len(str)-i-1]))
bytes[len(str)-i-1] = bytes[i]
fmt.Println("bytes[i]====",bytes[i])
fmt.Println("bytes[i]====",string(bytes[i]))
bytes[i]= tmp
}
str = string(bytes)
fmt.Println("str = ",str)
}
func testReverStringv2() {
var (
str = "你好呀sss"
r []rune = []rune(str)
)
fmt.Println("before str =",str)
//中文要使用转换后的r的长度
for i := 0;i<len(r)/2;i++{
tmp := r[len(r)-i-1]
fmt.Println("tmp ====",tmp)
r[len(r)-i-1] = r[i]
fmt.Println("r[i] =====",r[i])
r[i] = tmp
}
str = string(r)
fmt.Println("after str = ",str)
}
func testHuiWens() {
var (
str = "你好世界界世s好你"
r []rune = []rune(str)
)
for i := 0;i<len(r)/2;i++ {
tmp := r[len(r)-i-1]
r[len(r)-i-1] = r[i]
r[i] = tmp
}
str2 := string(r)
if str2 == str {
fmt.Println(str2,"is huiwen")
}else {
fmt.Println(str2,"is not huiwen")
}
}
func main() {
//testReverStringv1()
//testReverStringv2()
testHuiWens()
}