let greating : String = "Hello, world";
A string in Lense is a sequence of characters and implements Sequence<Character>
. Characters are UTF-16 code points.
Strings are fundamental types in Lense so they are specially supported by the language.
A string literal is just a text enclosed in double quotes.
let greating : String = "Hello, world";
String are mulit-line, so you can simply right
let greating : String = "Hello,
wold";
The line break , tab and spaces in the second line will be preserved.
If you need to use a Unicode special character, simply enclose its hexadecimal code as a natural within \{
and }
delimiters.
let definitionOfPi = "The value of \{#03C0} is the ratio between the circumference and the diameter of a circle"
You can concatenate strings using the ++
operator.
let name : String = "Alice";
let greating : String = "Hello, " ++ name;
However, you probably use interpolation a lot more that concatenation.
You can interpolate values inside literal strings using {{
and }}
as delimiters.
let name : String = "Alice";
let greating : String = "Hello, {{ name }}";
You can interpolate any expression
for (var i in 1..10){
Console.println("The {{ i }}th even number is {{ (i-1) * 2 }}")
}
Character corresponds to a UTF-16 code point. Literals are inclosed in a single quotes like 'a'
. A character is an Enumerable
, not a number (like in java) however you can still use some operators and some operations with `Natural`s.
let a = 'a';
let b = a.successor(); // 'b'
let c = a + 2; // 'c'