I am new to Go lang and trying to store : or %a in String using
str := fmt.Sprintf("dsfsd%a")
But when I try to print it, I am seeing "dsfsd%!a(Missing)".
Is there a way to store a sequence of characters like "%a" ":" etc.. in String?
CodePudding user response:
You need to escape the percent
str := fmt.Sprintf("dsfsd%%a")
CodePudding user response:
The problem is fmt.Sprintf
is treating it as format string
To solve this we can add format string to fmt.Sprintf
and pass value as data to format string
str := fmt.Sprintf("%s", "dsfsd%a")
Here working example