If I wanted to do the following:
fmt.Printf("Escape this -> %v... Do not escape this -> %v", "Unescaped")
How could I escape the first occurrence of %v
?
\%v
doesn't seem to work. Any ideas?
Characters in the format string are copied to the output or, if a % is encountered, are used to format an item. In addition to the standard formats, %b causes printf to expand backslash escape sequences (for example \n for newline), and %q outputs an item that can be used as shell input.
In some character encodings including BIG5 and GB18030, there are hundreds of characters that contain the encoding of backslash, and to escape those for printf , you'd need to insert a \ before each 0x5c byte within the encoding of those characters!
You can use %% for literal %
%% a literal percent sign; consumes no value
https://golang.org/pkg/fmt/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With