C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Raw: With the backtick character, escape sequences are ignored. The chars are treated as normal values.
Golang program that uses string literals, raw literals
package main
import "fmt"
func main() {
// The newline sequence is treated as a special value.
value1 := "cat\ndog"
fmt.Println(value1)
// The newline sequence is treated as two raw chars.
value2 := `cat\ndog`
fmt.Println(value2)
}
Output
cat
dog
cat\ndog
Tip: For creating repeating text, using Repeat() with a string literal is a good solution.
Golang program that uses Repeat
package main
import (
"fmt"
"strings"
)
func main() {
// Create a new string based on a repetition.
result := strings.Repeat("abc...", 3)
fmt.Println(result)
}
Output
abc...abc...abc...