我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在go中打印反斜杠?

I have the following code snippet:

const byte1 = 0x19;
const byte2 = 0x45;
msg := fmt.Sprintf("\\x%x\\x%x message", byte1, byte2)
log.Info("Learning go fmt", "msg", msg)

I get this:

msg="\\x19\\x45 message"

Why is the backslash duplicated? According to this website, \\ within a format should yield \.

@nilsocket's comment is correct. The problem is that I'm using the Ethereum log package. It unescapes the string. If I do:

fmt.Println("\\x%x\\x%x message", byte1, byte2)

It works perfectly fine.

近期文章

  • 使用get get获取展示框架时出错
  • Go实例的调试列表为空
  • golang json的元帅时间戳
  • dlv attach <pid> [二进制位置]拒绝访问
  • 使用golang.org/x/text/message格式化big.Rat
  • Git检出到Jenkins中的子目录失败
  • 如何从Golang中的XML文件提取多个字段
  • 新项目的Golang建筑问题
  • 我如何在json中响应时间毫秒零
  • 确定是否在解组时在json字符串中提供了值[重复]
  • 使用IntelliJ运行Go应用程序时加载配置文件
  • 使用glide在设置docker分发库中面临问题
  • 如何有条件地同时重定向和使用资产提供HTML
  • 客户端通过nginx取消请求是否传递给fastcgi
  • 如何从字节数组执行而不创建物理文件
  • 无法使用mikepb的go-serial打开串行端口
  • Beego框架在迁移时不会创建外键
  • 乱写WriteResponse
  • 用CGO构建git子模块
  • C++  如何把string类型转化成二进制的形式

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华