---
id: string-reference
title: String
description: Operations for strings.
hide_table_of_contents: true
---
import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
type string
type string
type string
A sequence of characters.
function length : string -> nat
val length : string -> nat
let length: string => nat
Get the size of a string.
[Michelson only supports ASCII strings](http://tezos.gitlab.io/whitedoc/michelson.html#constants)
so for now you can assume that each character takes one byte of storage.
```pascaligo
function string_size (const s: string) : nat is String.length(s)
```
> Note that `size` and `String.size` are *deprecated*.
```cameligo
let size_op (s: string) : nat = String.length s
```
> Note that `String.size` is *deprecated*.
```reasonligo
let size_op = (s: string): nat => String.length(s);
```
> Note that `String.size` is *deprecated*.
function sub : nat -> nat -> string -> string
val sub : nat -> nat -> string -> string
let sub: (nat, nat, string) => string
Get the substring of `s` between `pos1` inclusive and `pos2` inclusive. For example
the string "tata" given to the function below would return "at".
```pascaligo
function slice_op (const s : string) : string is String.sub(1n , 2n , s)
```
> Note that `string_slice` is *deprecated*.
```cameligo
let slice_op (s: string) : string = String.sub 1n 2n s
```
> Note that `String.slice` is *deprecated*.
```reasonligo
let slice_op = (s: string): string => String.sub(1n, 2n, s);
```
> Note that `String.slice` is *deprecated*.
function concat : string -> string -> string
val concat : string -> string -> string
let concat: (string, string) => string
Concatenate two strings and return the result.
```pascaligo
function concat_op (const s : string) : string is String.concat(s, "toto")
```
Alternatively:
```pascaligo
function concat_op_alt (const s : string) : string is s ^ "toto"
```
```cameligo
let concat_syntax (s: string) = String.concat s "test_literal"
```
Alternatively:
```cameligo
let concat_syntax_alt (s: string) = s ^ "test_literal"
```
```reasonligo
let concat_syntax = (s: string) => String.concat(s, "test_literal");
```
Alternatively:
```reasonligo
let concat_syntax_alt = (s: string) => s ++ "test_literal";
```