Go语言bool转string
source link: http://www.lzhpo.com/article/142
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Go语言bool转string
payload["fatca"] = strconv.FormatBool(frontOfficeCustomerRequestBody.FurtherInformation.FatcaIsUsCitizen)
if frontOfficeCustomerRequestBody.FurtherInformation.FatcaIsUsCitizen { payload["fatca"] = "true"} else { payload["fatca"] = "false"}
底层源代码
其实都一样的,只是strconv
包下面的FormatBool
方法帮你做好了封装。
"1", "t", "T", "true", "TRUE", "True" => true"0", "f", "F", "false", "FALSE", "False" => false
// Copyright 2009 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package strconv// ParseBool returns the boolean value represented by the string.// It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.// Any other value returns an error.func ParseBool(str string) (bool, error) { switch str { case "1", "t", "T", "true", "TRUE", "True": return true, nil case "0", "f", "F", "false", "FALSE", "False": return false, nil } return false, syntaxError("ParseBool", str)}// FormatBool returns "true" or "false" according to the value of b.func FormatBool(b bool) string { if b { return "true" } return "false"}// AppendBool appends "true" or "false", according to the value of b,// to dst and returns the extended buffer.func AppendBool(dst []byte, b bool) []byte { if b { return append(dst, "true"...) } return append(dst, "false"...)}
- 本文作者: lzhpo
- 本文链接: http://www.lzhpo.com/article/142
- 版权声明: 本文为本人原创文章,采用 CC BY 3.0 CN协议 ,可自由转载、引用,但需署名作者且注明文章出处。
Recommend
-
12
Bool型SSRF的思考与实践 Wulala ·
-
4
BOOL / bool / Boolean / NSCFBoolean Written by
-
5
Python中的bool 2017-07-20 18:02:52 +08 字数:1277 标签: Python bool类型
-
7
Collaborator rust-highfive commented
-
4
Copy link Contributor arya-k
-
4
How to implement Exp in Bool or Iff from the paper Extensibility for the Masses Join Stack Overflow to learn, share knowledge, and build your career. ...
-
2
Copy link Member fee1-dead commented...
-
4
Copy link Contributor KodrAus
-
7
How to Convert String to Bool in C# Posted by Code Maze | Feb 17, 2022 |
-
4
What’s the best way to convert a Swift String to a Bool? What’s A Valid Boolean? The answer depends a lot on what you consider to be a valid text representation of a boolean value. While parsing some XML...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK