Common escape characters in Golang

Posted Jun 15, 20201 min read

Case One

/*
  1. \t A tab stop to achieve the function of alignment
  2. \n Line break
  3. \\ a \
  4. \" One"
  5. \r a carriage return
*/

package main

import(
    "fmt"

)

func main() {
    fmt.Println("Name\tAge\tHometown\tAddress\njohn\t20\tHebei\tBeijing")
    fmt.Println("\\")
    fmt.Println("\"")
    fmt.Println("a\nb")
    fmt.Println("tom\rjac")
    fmt.Println("tom\tand\t\"jackk\"")
}

Case two

package main

import(
    "fmt"

)

func main() {
    fmt.Println("tome\tjack")
    //If you want to comment once ctrl +/means comment for the first time and uncomment for the second time
    fmt.Println("hello\nworld")
    fmt.Println("C:\\User\\Administrator\\Desktop\\Go language\\data")
    fmt.Println("tom said\"i love you\"")
    //\r carriage return, output from the front of the current line, overwriting the previous content
    fmt.Println("Tianlong Babu Snow Mountain Flying Fox\rZhang Fei is Powerful")
    fmt.Println("helloworldhelloworldhelloworldhelloworl\n",
        "dhelloworldhelloworldhelloworldhelloworldhelloworldhellowor\n",
        "ldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworl\n",
        "dhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhel\n",
        "loworldhelloworldhelloworldhelloworldhelloworldhelloworldhellowor\n",
        "ldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworld")
}