Strings

Literals, interpolation, escaping, and concatenation.

Rain strings are immutable double-quoted literals. Build them with #{expression} interpolation, + concatenation, str::format, or vakya(value) / toString(value) to stringify any value.

Numbers and booleans coerce to strings when interpolated or concatenated with a string. For arrays, maps, and nil, use vakya: + cannot combine those with strings directly. For str:: helpers (split, trim, format, …), see the str module under Modules.

Literals

Plain double-quoted strings. Use backslash escapes for special characters.

Literals
print "hello";
print "tabs\tand\nnewlines";
output
hello
tabs	and
newlines

Interpolation

Embed any expression inside a string with `#{...}`. Numbers and booleans coerce automatically.

Interpolation
var name = "Rain";
var version = 1;
var pi = 3.14159;
var flag = true;

print "hello #{name}!";
print "version #{version} of #{name}";
print "pi is #{pi}";
print "flag is #{flag}";
print "1 + 1 = #{version + version}";
output
hello Rain!
version 1 of Rain
pi is 3.14159
flag is true
1 + 1 = 2

Expressions inside #{}

Arithmetic and variables work inside `#{...}` and are evaluated before the string is built.

Expressions inside #{}
var x = 10;
var y = 20;
print "x=#{x} y=#{y}";
print "sum is #{x + y}";
output
x=10 y=20
sum is 30

Escaping quotes and #{}

Prefix with `\` to print a literal quote, hash, or `#{` without interpolating.

Escaping quotes and #{}
print "say \"hi\"";
print "not interp: \#{x}";
print "just a hash: \#";
output
say "hi"
not interp: #{x}
just a hash: #

Concatenation with +

Join strings with `+`. Numbers and booleans coerce to strings when one side is a string.

Concatenation with +
var name = "Rain";
var version = 1;

print "foo" + "bar";
print "name: " + name;
print "version: " + version;
print 1 + "x";
print "flag: " + true;
print "2 + 2 = " + (2 + 2);
output
foobar
name: Rain
version: 1
1x
flag: true
2 + 2 = 4

vakya / toString

Convert any value (including arrays, maps, and `nil`) to a string for printing or `+`.

vakya / toString
print vakya(42);
print vakya(3.14);
print toString(true);
print vakya(nil);
print toString(#[1, 2, 3]);
print vakya({"a": 1, "b": 2});

var n = 42;
print "the answer is " + vakya(n);
output
42
3.14
true
nil
#[1, 2, 3]
{"a": 1, "b": 2}
the answer is 42

str::format

Build a string from a template with `{0}`, `{1}`, … placeholders via the str module.

str::format
benutzen "str";

print str::format("hello {0}, you are {1} years old", "Rain", 5);
print str::format("pi is {0}", 3.14159);
output
hello Rain, you are 5 years old
pi is 3.14159

Split and join

Break a string into an array by delimiter, or combine array elements back into one string.

Split and join
benutzen "str";

var parts = str::split("a,b,c", ",");
print parts;
print str::join(parts, " - ");
output
#["a", "b", "c"]
a - b - c

Escape sequences

Backslash codes you can use inside any string literal.

SymbolDescription
\nNewline
\tTab
\rCarriage return
\\Backslash
\"Double quote inside a string
\0Null byte
\#Literal `#`
\#{...}Literal `#{...}` without interpolating

Notes