Ai
16 Star 69 Fork 54

ShirDon-廖显东/Go语言高级开发与实战-随书代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
1.2.3-strRev.go 906 Bytes
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2021-12-28 09:45 +08:00 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《Go语言高级开发与实战》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 知乎:https://www.zhihu.com/people/shirdonl
// 公众号:源码大数据
// 仓库地址:https://gitee.com/shirdonl/goAdvanced
// 仓库地址:https://github.com/shirdonl/goAdvanced
//++++++++++++++++++++++++++++++++++++++++
package main
import "fmt"
func main() {
//定义字符串
str := "123456789abc"
//调用反转函数
strRev := Reversal(str)
//打印
fmt.Println(str)
fmt.Println(strRev)
}
//反转字符串
func Reversal(a string) (re string) {
//将字符串转成rune数组
b := []rune(a)
//遍历
for i := 0; i < len(b)/2; i++ {
//交换
b[i], b[len(b)-i-1] = b[len(b)-i-1], b[i]
}
//转换为字符串类型
re = string(b)
return
}
//123456789abc
//cba987654321
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAdvanced.git
git@gitee.com:shirdonl/goAdvanced.git
shirdonl
goAdvanced
Go语言高级开发与实战-随书代码
0f051d9f4e35

搜索帮助