go语言byte类型报错cannot use "c" (type string) as type byte in assignment
练习Go修改字符串的时候遇到这个问题:cannot use "c" (type string) as type byte in assignment,代码如下:
package main
import "fmt"
func main() {
s := "hello"
c := []byte(s) // 将字符串转为[]byte类型
c[0] = 'c' // byte用''单引号包括字符 不然报错cannot use "c" (type string) as type byte in assignment
s2 := string(c) // 再转为string类型
fmt.Printf("%s\n", s2)
}
byte类型是使用单引号包括字符的,当时使用的双引号,所以报了这个错误,在此记录一下。
go语言byte类型报错cannot use "c" (type string) as type byte in assignment的更多相关文章
- flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法
flask+sqlite3+echarts2+ajax数据可视化报错: UnicodeDecodeError: 'utf8' codec can't decode byte 解决方法: 将 py文件和 ...
- Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence
Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal mul ...
- windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help
windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help 在windows8操作系统上安装 ...
- 运行报错:java.io.IOException: invalid constant type: 15
jdk,tomcat更新到jdk1.8与 tomcat8 运行报错:java.io.IOException: invalid constant type: 15 pom.xml文件中更新javassi ...
- MyEclipse上有main函数类运行报错:Editor does not contain a main type
MyEclipse下有main函数类运行报错:Editor does not contain a main type 出现这种问题的原因是,该java文件所在的包没有被MyEclipse认定为源码包. ...
- es报错org.frameworkset.elasticsearch.ElasticSearchException: {"error":{"root_cause":[{"type":"cluster_block_exception","reason":"blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];"}],
今天es在保存数据的时候报错 org.frameworkset.elasticsearch.ElasticSearchException: {"error":{"root ...
- Java报错: A component required a bean of type 'com.sirifeng.testmybatis.mapper.BookMapper' that could not be found.
在学习Spring-boot-mybatis时,报错A component required a bean of type 'com.sirifeng.testmybatis.mapper.BookM ...
- python2.7 报错(UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128))
报错: 原来用的python3.5版本后来改为2.7出现了这个错误里面的中文无法显示 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 ...
- 日期格式存入字符类型之后,再转回datetime类型报错
背景 最近我们迁移了一批服务器,因我们在azure portal 上新开的VM暂时默认只有英文系统,所以我们在开设好的数据库服务器的时候,都会重置数据库字符排序成中文,避免出现中文乱码问题,重置参考路 ...
随机推荐
- DOM结构及优化
1.DOM树中三种常见的DOM节点: 1>元素节点:上图中<a>,<h1>等都是元素节点,即标签 2>文本节点:向用户展示的内容,如...中的"文档标题& ...
- ButterKnife RadioGroup选择事件
ButterKnife 的点击事件都很清晰,在使用RadioGroup控件时的方法: <!-- 定义一组单选框 --> <RadioGroup android:id="@+ ...
- 学习笔记35—大话 Word和Excel
1.word中,加粗表格线条:设计---->笔画粗细. 2.Excel中,冻结某一行:点击工具栏中的视图→冻结空格→冻结单元格. 3.word中,输入卡方符号:插入----> 符号 --- ...
- ACM-ICPC 2018 沈阳赛区网络预赛 J Ka Chang
Ka Chang 思路: dfs序+树状数组+分块 先dfs处理好每个节点的时间戳 对于每一层,如果这一层的节点数小于sqrt(n),那么直接按照时间戳在树状数组上更新 如果这一层节点个数大于sqrt ...
- js判断安卓客户端或者是ios客户端,是否是微信浏览器
代码: function xaizai() { var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = ...
- Elasticsearch-基础介绍及索引原理分析
介绍 Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎,一个建立在全文搜索引擎 Apache Lucene(TM) 基础上的搜索引擎.当然 Elasticsearch 并不仅仅是 L ...
- MySQL的自动补全和语法高亮工具MyCli
官方地址: RHEL, Centos: We don't have packages for RHEL or Centos, yet. Instead, use pip to install mycl ...
- windows下如何通过git bash获取gitlab ssh公钥
Gitlab1. 安装git,从程序目录打开 "Git Bash" 2. 键入命令:ssh-keygen -t rsa -C "email@email.com" ...
- 廖雪峰网站:学习python函数—函数参数(三)
1.*args # 位置参数,计算x2的函数 def power(x): return x * x p = power(5) print(p) # 把power(x)修改为power(x, n),用来 ...
- csrf漏洞
漏洞原理:csrf全名为跨站请求伪造,是一种对网站的恶意利用,虽然听起来和xss很像,但是它们俩还是有很大的区别的.csrf是通过伪造来自受信任用户的请求来利用受信任的网站. 比如: 一个有csrf漏 ...