{"title":"Golang 字符串换行转换为数组:使用 strings.Split() 函数","description":"本文介绍如何在 Golang 中使用 strings.Split() 函数将字符串按照换行符拆分成数组。提供示例代码和输出结果,并解释 strings.Split() 函数的用法。","keywords":"Golang, 字符串, 换行, 数组, strings.Split(), 切片, 代码示例","content":"在 Golang 中,可以使用 strings.Split() 函数将字符串按照指定的分隔符拆分成数组。换行符可以用 \n 表示。\n\n以下是一个示例代码,将字符串按换行符拆分成数组:\n\ngo\npackage main\n\nimport (\n\t"fmt"\n\t"strings"\n)\n\nfunc main() {\n\tstr := "line1\nline2\nline3"\n\tarr := strings.Split(str, "\n")\n\t\n\tfmt.Println(arr)\n}\n\n\n输出结果为:\n\n\n[line1 line2 line3]\n\n\n注意,strings.Split() 函数返回的是一个 []string 类型的切片。"}

Golang 字符串换行转换为数组:使用 strings.Split() 函数

原文地址: https://www.cveoy.top/t/topic/pCZj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录