-4

how to print ascii-text in go language like python does like picture shown below

Using python

enter image description here

Using Golang

enter image description here

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39
Khaedir
  • 29
  • 1
  • 5
  • Try this: https://stackoverflow.com/a/4424560/8307258 – Radosław Załuska Oct 22 '17 at 08:00
  • You should always provide the code in such a way that a developer can copy and paste it easily. Either for easy debugging or to run the code themselves. Images showing code aren't easy to work with. For example. I was going to show you a solution with `fmt.Sprintf()`, but i'm not going to type the above out... – reticentroot Oct 22 '17 at 14:05

2 Answers2

2

The problem is that your text contains backtick (`), which happen to be delimiter character for golang's raw string literal. This situation is comparable to your python code had your text contains 3 consecutive double-quotes, which is the delimiter being used in your python code.

I don't see any quick escape from this situation without modifying your ascii text, as we don't have other options for raw string delimiter in golang like we have in python. You may want to store your ascii text in a text file and read it from there :

import (
    ....
    ....
    "io/ioutil"
)

func banner() string {
    b, err := ioutil.ReadFile("ascii.txt")
    if err != nil {
        panic(err)
    }
    fmt.Println(string(b))
}

If you're ok with slight modification to the ascii text source, then you can temporarily use other character that isn't used anywhere else in the ascii text to represent backtick, and then do string replacement to put the actual backtick in place. Or, you can use fmt.Sprintf to supply the problematic backtick :

ascii := fmt.Sprintf(`....%c88b...`, '`')
fmt.Println(ascii)
// output:
// ....`88b...
har07
  • 88,338
  • 12
  • 84
  • 137
  • thank you for helping me, I just found one ascii text style that doesn't contain backtick character. this problem has been solved. – Khaedir Oct 24 '17 at 08:05
0

Yes but you have to split lines with backtick and put them quoted into standard double quote .

...  +
“888 6(,   ` ‘ “ + 
...
Eugene Lisitsky
  • 12,113
  • 5
  • 38
  • 59