GO语言实现txt文本多行合并为一行

windows系统txt文件

input.txt多行合并为一行

package main

import (
	"fmt"
	"io/ioutil"
	"strings"
)

func main() {
	content, err := ioutil.ReadFile("E:\\gin_demo\\demo30DNF\\youhua\\input.txt")
	if err != nil {
		fmt.Println("Error reading input file:", err)
		return
	}

	processedContent := strings.ReplaceAll(string(content), "\r\n", "")

	err = ioutil.WriteFile("E:\\gin_demo\\demo30DNF\\youhua\\output.txt", []byte(processedContent), 0644)
	if err != nil {
		fmt.Println("Error writing output file:", err)
		return
	}

	fmt.Println("Successfully removed newlines and saved to output.txt.")
}

你可能感兴趣的:(golang,服务器,开发语言)