doulianxing4015 2018-06-29 20:30
浏览 642

如何使用Sprintf对YAML文件采用的字符串中的单引号进行转义

I'm using Go but I'm having issues while trying to get an array that contains a single quote, I'm making a query structure to create a .sql file with that query, the issue is with an array field that is adding double quotes instead of a single quote.

This is what I have:

Yaml File:

Name: 'Myname'
Age: 9
Dimensions ['go', 'lang']

Go code Syntaxis:

var Query string = "";
Query = fmt.Sprintf("INSERT INTO persons (name, age, dimensions) VALUES ('%s', %d, %q)")

OUTPUT:

 Query:
 INSERT INTO persons (name, age, dimensions) VALUES ('MyName', 9, ["go", "lang"])

I don't want "go" and "lang" double quoted, I want it as the YAML file came, with single quote.

Is supposed that "%q" escape the single quote...

any idea what to do?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 slam rangenet++配置
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊