String Building

Tengo has no string interpolation. Use + for simple concatenation, fmt.sprintf for formatted strings, and text.join to assemble arrays of parts into a single string.

fmt := import("fmt")
text := import("text")
s := "Hello" + ", " + "Tengo!"
fmt.println(s)
name := "world"
n := 42
fmt.println(fmt.sprintf("Hello, %s! The answer is %d.", name, n))
fmt.println(fmt.sprintf("pi ≈ %.4f", 3.14159))
fmt.println(fmt.sprintf("%-10s %5d", "score:", 99))
parts := []
for i := 1; i <= 5; i++ {
    parts = append(parts, string(i))
}
fmt.println(text.join(parts, " + ") + " = 15")
fmt.println(text.repeat("=-", 10))
fmt.println(text.trim_space("   padded   "))
fmt.println(text.trim("***hello***", "*"))
fmt.println(text.has_prefix("Tengo", "Ten"))
fmt.println(text.has_suffix("Tengo", "go"))

try it

Hello, Tengo!
Hello, world! The answer is 42.
pi ≈ 3.1416
score:        99
1 + 2 + 3 + 4 + 5 = 15
=-=-=-=-=-=-=-=-=-=-
padded
hello
true
true
loading…