Go实战--go中一些有用的代码片段(The way to go)

83 篇文章 128 订阅 ¥29.90 ¥99.00
本文分享了一些关于Go语言(golang)的实用代码片段,包括如何改变字符串值、获取子字符串、遍历字符串输出、在二维数组或切片中查询值、检查map中是否存在key以及检测channel是否关闭等操作。
摘要由CSDN通过智能技术生成

生命不止,继续 go go go !!!

今天跟大家分享一些有用的,简单的golang代码片段。

改变string的值
首先我们要知道,在golang中,string是不可变的:

    str := "hello"
    str[0] = 'c'

编译错误:cannot assign to str[0]

正确的做法:

package main

import (
    "fmt"
)

func main() {
    str := "hello"
    c := []
The Way to Go,: A Thorough Introduction to the Go Programming Language 英文书籍,已Cross the wall,从Google获得书代码,分享一下。喜欢请购买正版。 目录如下: Contents Preface................................................................................................................................. xix PART 1—WHY LEARN GO—GETTING STARTED Chapter 1—Origins, Context and Popularity of Go...............................................................1 1.1 Origins and evolution................................................................................................1 1.2 Main characteristics, context and reasons for developing a new language....................4 1.2.1 Languages that influenced Go.........................................................................4 1.2.2 Why a new language?......................................................................................5 1.2.3 Targets of the language....................................................................................5 1.2.4 Guiding design principles...............................................................................7 1.2.5 Characteristics of the language........................................................................7 1.2.6 Uses of the language........................................................................................8 1.2.7 Missing features?.............................................................................................9 1.2.8 Programming in Go......................................................................................10 1.2.9 Summary......................................................................................................10 Chapter 2—Installation and Runtime Environment............................................................11 2.1 Platforms and architectures.....................................................................................11 (1) The gc Go-compilers:...........................................................
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一苇渡江694

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值