2020-03-16 07:50:12 +01:00
|
|
|
// This script tests string operations
|
|
|
|
|
2016-03-02 14:37:28 +01:00
|
|
|
print("hello");
|
2020-03-16 07:50:12 +01:00
|
|
|
print("this\nis \\ nice"); // escape sequences
|
2021-03-30 15:33:30 +02:00
|
|
|
print("0x40 hex is \x40"); // hex escape sequence
|
|
|
|
print("Unicode fun: \u2764"); // Unicode escape sequence
|
2020-03-16 07:50:12 +01:00
|
|
|
print("more fun: \U0001F603"); // Unicode escape sequence
|
|
|
|
print("foo" + " " + "bar"); // string building using strings
|
|
|
|
print("foo" < "bar"); // string comparison
|
|
|
|
print("foo" >= "bar"); // string comparison
|
|
|
|
print("the answer is " + 42); // string building using non-string types
|
|
|
|
|
2020-08-14 08:08:11 +02:00
|
|
|
let s = "\u2764 hello, world! \U0001F603"; // string variable
|
2021-04-04 17:22:45 +02:00
|
|
|
print(`length=${s.len}`); // should be 17
|
2020-03-16 07:50:12 +01:00
|
|
|
|
2020-06-27 15:19:53 +02:00
|
|
|
s[s.len-3] = '?'; // change the string
|
2021-04-04 17:22:45 +02:00
|
|
|
print(`Question: ${s}`); // should print 'Question: hello, world?'
|
2021-03-30 15:33:30 +02:00
|
|
|
|
|
|
|
// Line continuation:
|
|
|
|
let s = "This is a long \
|
|
|
|
string constructed using \
|
|
|
|
line continuation";
|
|
|
|
|
2021-04-04 17:22:45 +02:00
|
|
|
// String interpolation
|
|
|
|
print(`One string: ${s}`);
|
2021-03-30 15:33:30 +02:00
|
|
|
|
|
|
|
// Multi-line literal string:
|
|
|
|
let s = `
|
|
|
|
\U0001F603 This is a multi-line
|
|
|
|
"string" with \t\x20\r\n
|
|
|
|
made using multi-line literal
|
|
|
|
string syntax.
|
|
|
|
`;
|
|
|
|
|
|
|
|
print(s);
|
|
|
|
|
|
|
|
print(">>> END <<<");
|