Table of Contents

Basics of string tutorial

Text strings are conventionally interpreted as UTF-8-encoded sequences of Unicode code points (runes)

Conversions to and from a string type discussion

int -> string
[]byte -> string
[]rune -> string
string -> []byte
string -> []rune

Normalize new lines (CRLF -> LF) howto

func Normalize(b []byte) []byte {
    // Win -> Unix: replace CR LF with LF
    b = bytes.Replace(b, []byte("\r\n"), []byte("\n"), -1)
    // Mac -> Unix: replace CF with LF
    b = bytes.Replace(b, []byte("\r"), []byte("\n"), -1)
    return b