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.
print "hello";
print "tabs\tand\nnewlines";hello tabs and newlines
Interpolation
Embed any expression inside a string with `#{...}`. Numbers and booleans coerce automatically.
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}";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.
var x = 10;
var y = 20;
print "x=#{x} y=#{y}";
print "sum is #{x + y}";x=10 y=20 sum is 30
Escaping quotes and #{}
Prefix with `\` to print a literal quote, hash, or `#{` without interpolating.
print "say \"hi\"";
print "not interp: \#{x}";
print "just a hash: \#";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.
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);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 `+`.
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);42
3.14
true
nil
#[1, 2, 3]
{"a": 1, "b": 2}
the answer is 42str::format
Build a string from a template with `{0}`, `{1}`, … placeholders via the str module.
benutzen "str";
print str::format("hello {0}, you are {1} years old", "Rain", 5);
print str::format("pi is {0}", 3.14159);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.
benutzen "str";
var parts = str::split("a,b,c", ",");
print parts;
print str::join(parts, " - ");#["a", "b", "c"] a - b - c
Escape sequences
Backslash codes you can use inside any string literal.
| Symbol | Description |
|---|---|
\n | Newline |
\t | Tab |
\r | Carriage return |
\\ | Backslash |
\" | Double quote inside a string |
\0 | Null byte |
\# | Literal `#` |
\#{...} | Literal `#{...}` without interpolating |