A Simple Txt File Processing Tool by Golang


本文摘自网络,作者,侵删。


title: "A Simple Txt File Processing Tool by Golang"
date: 2021-01-31T10:04:51+08:00
draft: true
tags: ['go']
author: "dadigang"
author_cn: "大地缸"
personal: "http://www.real007.cn"


关于作者

http://www.real007.cn/about

package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
    "strings"
)

func main() {
    fileName := "0"
    file, err := os.OpenFile(fileName, os.O_RDWR, 0666)
    if err != nil {
        fmt.Println("Open file error!", err)
        return
    }
    defer file.Close()

    buf := bufio.NewReader(file)
    for {
        line, err := buf.ReadString('\n')
        line = strings.TrimSpace(line)

        //fmt.Println(strings.ReplaceAll(line, " ", "-"))

        fmt.Printf("[%s](https://github.com/topics/%s)\n\n", line, line)
        if err != nil {
            if err == io.EOF {

                break
            } else {
                return
            }
        }
    }
}

本文来自:简书

感谢作者:大地缸

查看原文:A Simple Txt File Processing Tool by Golang

相关阅读 >>

Go 中使用控制流

在 bigcache 中存储任意类型(interface{})

知乎从python转为Go,是不是代表Go比python好?

聊聊dubbo-Go-proxy的jtypes

单核cpu下Golang调度及抢占式调度的实现

一文读懂云原生 Go-zero 微服务框架

关于Golang 指针理解

Gocn酷Go推荐】ip2location 解析 ip 地址库

Golang 是否需要orm

关于Golang中方法的receiver为指针和不为指针的区别

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...