ligo/gitlab-pages/docs/language-basics/strings.md
Matej Šima 628d818163 Revert "Merge with dev"
This reverts commit 6ffe220d928dc3137496bcea0cc0f4d72edc2846.
2019-11-07 23:19:27 +00:00

1.6 KiB

id title
strings Strings

Strings are defined using the built-in string type like this:

const a: string = "Hello Alice";
let a: string = "Hello Alice"

Concatenating strings

Strings can be concatenated using the ^ operator.

const name: string = "Alice";
const greeting: string = "Hello";
// Hello Alice
const full_greeting: string = greeting ^ " " ^ name;
// Hello Alice! (alternatively)
const full_greeting_exclamation: string = string_concat(full_greeting, "!");
let name: string = "Alice"
let greeting: string = "Hello"
let full_greeting: string = greeting ^ " " ^ name

Slicing strings

Strings can be sliced using the syntax specific built-in built-in function:

const name: string = "Alice";
// slice = "A"
const slice: string = string_slice(0n, 1n, name);
let name: string = "Alice"
let slice: string = String.slice 0n 1n name

⚠️ Notice that the offset and slice length are nats

Aquiring the length of a string

The length of a string can be found using the syntax specific built-in function:

const name: string = "Alice";
// length = 5
const length: nat = size(name);
let name: string = "Alice"
let length: nat = String.size name