I need to create a string with html link inside.
fmt.Sprint("<a href=\"%s\">%s</a>", "/myUrl", "link text");
Expected result is
<a href="/myUrl">link text</a>
But real result is
<a href="%s">%s</a>/myUrllink text
What am I doing wrong?
By the way, I have this warning in GoLand
fmt.Sprint
will print the string as it is. If you want to format the string, you should use fmt.Sprintf
.
The SO community can be very harsh on beginners, if people do not like what you have written or how you worded the question you will get down voted. Don't fool yourself thinking people are here to help, they only care for the reputation.
Luckily in Go
we have pretty good docs. If you ever think something is not working properly, chances are that a glance at the docs website will be enough to get you going.
func Sprintf(format string, a ...interface{}) string
Sprintf formats according to a format specifier and returns the resulting string.
func Sprint(a ...interface{}) string
Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.
Also fmt
is pretty big and very useful standard package with a good documentation. You can find a lot of different I/O functions there.
Also it is perkily and weird to write "incorrect result" if you hasn't read a documentation.