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暂时默认只有英文系统,所以我们在开设好的数据库服务器的时候,都会重置数据库字符排序成中文,避免出现中文乱码问题,重置参考路 ...
随机推荐
- 你真的了解restful api吗?
前言 在以前,一个网站的完成总是“all in one”,页面,数据,渲染全部在服务端完成,这样做的最大的弊端是后期维护,扩展极其痛苦,开发人员必须同时具备前后端知识.于是慢慢的后来兴起了前后端分离的 ...
- 力扣(LeetCode) 9.回文数
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...
- JS添加/移除事件
事件的传播方式 <div id="father"> <div id="son"></div> </div> &l ...
- mac软件
1. http://www.ifunmac.com/ 2.Mac安装软件时提示已损坏的解决方法 http://www.jianshu.com/p/3d04a2292fcd 3.mac以后有时间在装的软 ...
- C#中统计一个过程消耗的时间
使用Unity进行的测试,代码如下: using System.Collections; using System.Collections.Generic; using UnityEngine; us ...
- 图片方向 image orientation Exif
更新 : 2019-01-02 refer https://stackoverflow.com/questions/3129099/how-to-flip-images-horizontally-wi ...
- 对nginx进行平滑升级
1.查看服务器当前nginx版本 [root@instance-hwl9ix5l licenses]# nginx -v #查看版本 nginx: nginx version: n ...
- css趣味案例:画三角形
代码: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&q ...
- patch-test-and-proc
实验环境 Ubuntu 14.04.5 LTS Linux - 4.15.6 为单个文件进程补丁操作 在桌面 Desktop 建立文件夹 patch ,作为实验用,然后进入patch 文件夹.建立测试 ...
- 第十章 Call 和 Ret 指令
引言 想想程序之间的加载返回过程. call 和 ret 指令都是转移指令,它们都修改 IP,或同时修改 CS 和 IP. call 和 ret 经常被共同用来实现自程序的设计. 这一章,我们讲解 c ...