<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>String on Tony Bai</title><link>https://tonybai.com/tags/string/</link><description>Recent content in String on Tony Bai</description><generator>Hugo</generator><language>zh-cn</language><copyright>2004-2026 Tony Bai. 版权所有.</copyright><lastBuildDate>Fri, 17 Oct 2025 00:00:00 +0800</lastBuildDate><atom:link href="https://tonybai.com/tags/string/index.xml" rel="self" type="application/rss+xml"/><item><title>收到非 UTF-8 文本怎么办？Go 字符集检测的探索与实践</title><link>https://tonybai.com/2025/10/17/detect-charset-in-go/</link><pubDate>Fri, 17 Oct 2025 00:00:00 +0800</pubDate><guid>https://tonybai.com/2025/10/17/detect-charset-in-go/</guid><description>本文永久链接 – https://tonybai.com/2025/10/17/detect-charset-in-go 大家好，我是Tony Bai。 在上一篇关于 Go 语言 string 与 rune 设计哲学的文章发布后，我收到了许多精彩的反馈。其中，一位读者提出了一个极具现实意义的后续问题：“既然 Go 的世界以 UTF-8 为中心，那么当我们从外部系统（如老旧的文件、非标准的 API）...</description></item><item><title>string 与 rune 的设计哲学：为什么Go 程序员很少为“乱码”烦恼？</title><link>https://tonybai.com/2025/10/13/string-and-rune-in-go/</link><pubDate>Mon, 13 Oct 2025 00:00:00 +0800</pubDate><guid>https://tonybai.com/2025/10/13/string-and-rune-in-go/</guid><description>本文永久链接 – https://tonybai.com/2025/10/13/string-and-rune-in-go 大家好，我是Tony Bai。 &amp;gt; “为什么我的字符又乱码了？！” 这是一个在软件开发历史上，曾让无数程序员彻夜难眠的哀嚎。处理文本，是编程中最基础的任务之一，但其背后关于编码 (Encoding) 和字符集 (Character Set) 的水，远比看起来要深。正如 Joe...</description></item><item><title>Go 考古：Slice 的“隐秘角落”——只读切片与扩容策略的权衡</title><link>https://tonybai.com/2025/10/02/go-archaeology-slice/</link><pubDate>Thu, 02 Oct 2025 00:00:00 +0800</pubDate><guid>https://tonybai.com/2025/10/02/go-archaeology-slice/</guid><description>本文永久链接 – https://tonybai.com/2025/10/02/go-archaeology-slice 大家好，我是Tony Bai。 slice（切片），可以说是 Go 语言中最重要、也最常用的数据结构，没有之一。我们每天都在使用它，尤其是 append 函数，它就像一个魔术师，总能“恰到好处”地为我们管理好底层数组的容量，让我们几乎感受不到内存分配的烦恼。 但你是否想过，这份...</description></item><item><title>从 Rob Pike 的提案到社区共识：Go 或将通过 new(v) 彻底解决指针初始化难题</title><link>https://tonybai.com/2025/08/17/create-pointer-to-simple-types/</link><pubDate>Sun, 17 Aug 2025 00:00:00 +0800</pubDate><guid>https://tonybai.com/2025/08/17/create-pointer-to-simple-types/</guid><description>本文永久链接 – https://tonybai.com/2025/08/17/create-pointer-to-simple-types 大家好，我是Tony Bai。 在 Go 中创建一个指向基本类型（如 int 或 string）的指针，为何比创建一个指向结构体的指针更繁琐？这个长期存在的“人体工程学”问题，由 Go 语言的共同创造者之一 **Rob Pike** 在提案 #45624 中...</description></item><item><title>Go 1.24用户报告：Datadog如何借助 Swiss Tables版map节省数百 GB 内存？</title><link>https://tonybai.com/2025/07/22/go-swiss-table-map-user-report/</link><pubDate>Tue, 22 Jul 2025 00:00:00 +0800</pubDate><guid>https://tonybai.com/2025/07/22/go-swiss-table-map-user-report/</guid><description>本文永久链接 – https://tonybai.com/2025/07/22/go-swiss-table-map-user-report 大家好，我是Tony Bai。 Datadog 的故事始于一次对Go 1.24内存回归问题的追踪。在与 Go 社区协作修复了该问题后，他们在部署修复版本的过程中，观察到了一个意料之外的现象：在高流量环境中，内存使用不仅恢复了正常，甚至**大幅下降**。一个名...</description></item><item><title>揭秘Go语言中的rune：一段跨越30年的Plan 9往事与UTF-8的诞生传奇</title><link>https://tonybai.com/2025/05/16/how-rune-came/</link><pubDate>Fri, 16 May 2025 00:00:00 +0800</pubDate><guid>https://tonybai.com/2025/05/16/how-rune-came/</guid><description>揭秘Go语言中的rune：一段跨越30年的Plan 9往事与UTF-8的诞生传奇 - Tony Bai =============== Tony Bai 一个程序员的心路历程 * Google Go语言编码风格规范 * Google Go语言编码风格规范：指南篇 * Google Go语言编码风格规范：决定篇 * Google Go语言编码风格规范：最佳实践篇 * Go语言第一课FAQ * Go语...</description></item><item><title>Go 1.25规范大扫除：移除“Core Types”，为更灵活的泛型铺路</title><link>https://tonybai.com/2025/03/27/remove-coretypes-from-go-spec/</link><pubDate>Thu, 27 Mar 2025 00:00:00 +0800</pubDate><guid>https://tonybai.com/2025/03/27/remove-coretypes-from-go-spec/</guid><description>Go 1.25规范大扫除：移除“Core Types”，为更灵活的泛型铺路 - Tony Bai =============== Tony Bai 一个程序员的心路历程 * Google Go语言编码风格规范 * Google Go语言编码风格规范：指南篇 * Google Go语言编码风格规范：决定篇 * Google Go语言编码风格规范：最佳实践篇 * Go语言第一课FAQ * Go语言进阶...</description></item><item><title>“类型名称”在Go语言规范中的演变</title><link>https://tonybai.com/2024/09/24/the-evolution-of-type-name-in-go-spec/</link><pubDate>Tue, 24 Sep 2024 00:00:00 +0800</pubDate><guid>https://tonybai.com/2024/09/24/the-evolution-of-type-name-in-go-spec/</guid><description>“类型名称”在Go语言规范中的演变 | Tony Bai =============== Tony Bai一个程序员的心路历程 * Google Go语言编码风格规范 * Google Go语言编码风格规范：指南篇 * Google Go语言编码风格规范：决定篇 * Google Go语言编码风格规范：最佳实践篇 * Go语言第一课FAQ * 关于我 * 文章列表 “类型名称”在Go语言规范中的演...</description></item><item><title>Go是一门面向对象编程语言吗</title><link>https://tonybai.com/2023/03/12/is-go-object-oriented/</link><pubDate>Sun, 12 Mar 2023 00:00:00 +0800</pubDate><guid>https://tonybai.com/2023/03/12/is-go-object-oriented/</guid><description>本文永久链接 – https://tonybai.com/2023/03/12/is-go-object-oriented Go语言已经开源13年了，在近期TIOBE发布的2023年3月份的编程语言排行榜中，Go再次冲入前十，相较于Go在2022年底的排名提升了2个位次： 《Go语言第一课》专栏中关于Go在这两年开始飞起的“预言”也正在逐步成为现实^\_^，大家学习Go的热情也在快速提升， 《Go...</description></item><item><title>十分钟入门Go语言</title><link>https://tonybai.com/2023/02/23/learn-go-in-10-min/</link><pubDate>Thu, 23 Feb 2023 00:00:00 +0800</pubDate><guid>https://tonybai.com/2023/02/23/learn-go-in-10-min/</guid><description>本文永久链接 – https://tonybai.com/2023/02/23/learn-go-in-10-min 本文旨在带大家快速入门Go语言，期望小伙伴们在花费十分钟左右通读全文后能对Go语言有一个初步的认知，为后续进一步深入学习Go奠定基础。 本文假设你完全没有接触过Go，你可能是一名精通其他编程语言的程序员，也可能是毫无编程经验、刚刚想转行为码农的热血青年。 编程简介 ---- 编程就...</description></item><item><title>Go编程语言与环境：万字长文复盘导致Go语言成功的那些设计决策[译]</title><link>https://tonybai.com/2022/05/04/the-paper-of-go-programming-language-and-environment/</link><pubDate>Wed, 04 May 2022 00:00:00 +0800</pubDate><guid>https://tonybai.com/2022/05/04/the-paper-of-go-programming-language-and-environment/</guid><description>本文永久链接 – https://tonybai.com/2022/05/04/the-paper-of-go-programming-language-and-environment 美国计算机学会通讯(Communications of the ACM)期刊2022年5月第65卷第5期将发表一篇有关Go语言的综述类Paper：《Go编程语言与环境》，这类综述类文章只有资深的Go核心团队的人才“...</description></item><item><title>Go字符串比较，终于有人讲清楚了</title><link>https://tonybai.com/2022/04/18/inside-go-string-comparison/</link><pubDate>Mon, 18 Apr 2022 00:00:00 +0800</pubDate><guid>https://tonybai.com/2022/04/18/inside-go-string-comparison/</guid><description>本文永久链接 – https://tonybai.com/2022/04/18/inside-go-string-comparison 西娅(Thea)是一个刚刚入门Go语言的妹子程序员，今天她遇到了一个让她“surprise”的问题。下面就是那段让妹子西娅困惑的Go代码： func main() { s1 := &amp;#34;12345&amp;#34; s2 := &amp;#34;2&amp;#34; fmt.Println(`&amp;#34;12345&amp;#34; &amp;gt; &amp;#34;...</description></item><item><title>“Go语言第一课”结课了</title><link>https://tonybai.com/2022/02/17/go-first-course-close/</link><pubDate>Thu, 17 Feb 2022 00:00:00 +0800</pubDate><guid>https://tonybai.com/2022/02/17/go-first-course-close/</guid><description>本文永久链接 – https://tonybai.com/2022/02/17/go-first-course-close 就在家家户户刚刚过完虎年元宵佳节之际，我的Go语言专栏：《Tony Bai·Go语言第一课》也迎来了它的最后一讲**结术语**。 这门专栏的撰写开始于2021年5月中旬，翻看我用于管理专栏原始文稿的github仓库的commit log记录，这一有纪念价值的日子被精确定位在5...</description></item><item><title>惊了！原来Go语言也有隐式转型</title><link>https://tonybai.com/2021/12/02/go-has-implicit-type-convertion/</link><pubDate>Thu, 02 Dec 2021 00:00:00 +0800</pubDate><guid>https://tonybai.com/2021/12/02/go-has-implicit-type-convertion/</guid><description>本文永久链接 – https://tonybai.com/2021/12/02/go-has-implicit-type-convertion 我的极客时间专栏《Go语言第一课》上线后收到了很多学员的反馈，大家提出了很多显然是经过认真思考的高水平问题。有些时候我也会被这些问题所“难倒”，比如昨天我在后台看到的这个问题。 我把这个问题整理为下面代码文本，方便大家copy和重现问题： ``` pack...</description></item><item><title>Go 1.17新特性详解：使用基于寄存器的调用惯例</title><link>https://tonybai.com/2021/08/20/using-register-based-calling-convention-in-go-1-17/</link><pubDate>Fri, 20 Aug 2021 00:00:00 +0800</pubDate><guid>https://tonybai.com/2021/08/20/using-register-based-calling-convention-in-go-1-17/</guid><description>本文永久链接 – https://tonybai.com/2021/08/20/using-register-based-calling-convention-in-go-1-17 除了Go语言特性与go module有重要变化之外，Go编译器与Go运行时也都有着优化与改进，这两方面的变化对Go程序的构建与运行影响巨大。在这个系列的最后一篇中，我们来看看编译器与运行时中那些值得关注的变化。 1. ...</description></item><item><title>Go语言的“黑暗角落”：盘点学习Go语言时遇到的那些陷阱[译]（第二部分）</title><link>https://tonybai.com/2021/03/29/darker-corners-of-go-part2/</link><pubDate>Mon, 29 Mar 2021 00:00:00 +0800</pubDate><guid>https://tonybai.com/2021/03/29/darker-corners-of-go-part2/</guid><description>本文翻译自Rytis Bieliunas的文章《Darker Corners of Go》。 第一部分参见[《Go语言的“黑暗角落”：盘点学习Go语言时遇到的那些陷阱\[译\]（第一部分）》](https://tonybai.com/2021/03/29/darker-corners-of-go-part1) 7\. 字符串和字节数组 ------------ 1) Go中的字符串 Go字符串的内...</description></item><item><title>Go语言的“黑暗角落”：盘点学习Go语言时遇到的那些陷阱[译]（第一部分）</title><link>https://tonybai.com/2021/03/29/darker-corners-of-go-part1/</link><pubDate>Mon, 29 Mar 2021 00:00:00 +0800</pubDate><guid>https://tonybai.com/2021/03/29/darker-corners-of-go-part1/</guid><description>本文翻译自Rytis Bieliunas的文章《Darker Corners of Go》。 &amp;gt; 译注：若干年前，Kyle Quest曾发过一篇名为“50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs”的文章，仿效著名的《C Traps and Pitfalls》编写了50条Go语言的陷阱与缺陷，一时在G...</description></item><item><title>对Go 1.16 io/fs设计的第一感觉：得劲儿！</title><link>https://tonybai.com/2021/03/23/io-fs-interface-is-an-excellent-design/</link><pubDate>Tue, 23 Mar 2021 00:00:00 +0800</pubDate><guid>https://tonybai.com/2021/03/23/io-fs-interface-is-an-excellent-design/</guid><description>1\. 设计io/fs的背景 Go语言的接口是Gopher最喜欢的语法元素之一，其隐式的契约满足和“当前唯一可用的泛型机制”的特质让其成为面向组合编程的强大武器，其存在为Go建立事物抽象奠定了基础，同时也是建立抽象的主要手段。 Go语言从诞生至今，最成功的接口定义之一就是io.Writer和io.Reader接口： type Writer interface { Write(p []byte) (...</description></item><item><title>Go泛型真的要来了！最早在Go 1.17版本支持</title><link>https://tonybai.com/2020/06/18/the-go-generics-is-coming-and-supported-in-go-1-17-at-the-earliest/</link><pubDate>Thu, 18 Jun 2020 00:00:00 +0800</pubDate><guid>https://tonybai.com/2020/06/18/the-go-generics-is-coming-and-supported-in-go-1-17-at-the-earliest/</guid><description>Go官博今晨发表了Go核心团队两位大神Ian Lance Taylor和Go语言之父之一的Robert Griesemer撰写的文章“The Next Step for Generics”，该文介绍了Go泛型(Go Generics)的最新进展和未来计划。 2019年中旬，在Go 1.13版本发布前夕的GopherCon 2019大会上，Ian Lance Taylor代表Go核心团队做了有关Go...</description></item><item><title>Go 1.14中值得关注的几个变化</title><link>https://tonybai.com/2020/03/08/some-changes-in-go-1-14/</link><pubDate>Sun, 08 Mar 2020 00:00:00 +0800</pubDate><guid>https://tonybai.com/2020/03/08/some-changes-in-go-1-14/</guid><description>可能是得益于2020年2月26日Go 1.14的发布，在2020年3月份的TIOBE编程语言排行榜上，Go重新进入TOP 10，而去年同期Go仅排行在第18位。虽然Go语言以及其他主流语言在榜单上的“上蹿下跳”让这个榜单的权威性饱受质疑:)，但Go在这样的一个时间节点能进入TOP 10，对于Gopher和Go社区来说，总还是一个不错的结果。并且在一定层度上说明：Go在努力耕耘十年后，已经在世界主流...</description></item><item><title>记一次go panic问题的解决过程</title><link>https://tonybai.com/2019/04/04/notes-about-fixing-a-go-panic-problem/</link><pubDate>Thu, 04 Apr 2019 00:00:00 +0800</pubDate><guid>https://tonybai.com/2019/04/04/notes-about-fixing-a-go-panic-problem/</guid><description>一. Panic问题概述 ------------ 本周收到客户在bugclose上填写的一个issue：添加一个下发通道后，pushd程序panic并退出了！程序panic时输出的stacktrace信息摘录如下： panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: se...</description></item><item><title>写Go代码时遇到的那些问题[第3期]</title><link>https://tonybai.com/2018/04/06/the-problems-i-encountered-when-writing-go-code-issue-3rd/</link><pubDate>Fri, 06 Apr 2018 00:00:00 +0800</pubDate><guid>https://tonybai.com/2018/04/06/the-problems-i-encountered-when-writing-go-code-issue-3rd/</guid><description>我有一个习惯，那就是随时记录下编程过程中遇到的问题（包括问题现场、问题起因以及对问题的分析），并喜欢阶段性的对一段时间内的**编码过程的得与失**进行回顾和总结。内容可以包括：对编程语法的新认知、遇坑填坑的经历、一些让自己豁然开朗的小tip/小实践等。记录和总结的多了，感觉有价值的，就成文发在博客上的；一些小的点，或是还没有想清楚的事情，或思路没法结构化统一的，就放在资料库里备用。“写Go代码时遇...</description></item><item><title>字符串拷贝密码</title><link>https://tonybai.com/2006/06/26/the-secret-of-string-copy/</link><pubDate>Mon, 26 Jun 2006 00:00:00 +0800</pubDate><guid>https://tonybai.com/2006/06/26/the-secret-of-string-copy/</guid><description>在近期的一次工作交接中，在我的代码中发现了很多’安全隐患’，主要是以’字符串拷贝’为主。这种安全漏洞在C编程中是较为常见的，防范起来也较为容易，这里我们就来一起探索一下’字符串拷贝’的’密码’。 在正常情况下，我们在考量目的缓冲区大小时都会以源缓冲区大小作为依据的，一般会适当的比源缓冲区多出一些空间，其中一种’居中’状况：即sizeof(dstbuf) = strlen(srcbuf) + 1。 ...</description></item></channel></rss>