---
title: Std.String
---

Unicode string operations: slicing, searching, casing, and more.

## Functions

### length

```saga
fun length : (s: String) -> Int
```

Returns the number of grapheme clusters in the string.

### is_empty

```saga
fun is_empty : String -> Bool
```

Returns True if the string is empty.

### graphemes

```saga
fun graphemes : (s: String) -> List String
```

Splits a string into its individual grapheme clusters.

### trim

```saga
fun trim : (s: String) -> String
```

Removes leading and trailing whitespace.

### to_lower

```saga
fun to_lower : (s: String) -> String
```

Converts all characters to lowercase.

### to_upper

```saga
fun to_upper : (s: String) -> String
```

Converts all characters to uppercase.

### reverse

```saga
fun reverse : (s: String) -> String
```

Reverses the string.

### slice

```saga
fun slice : (start: Int) -> (len: Int) -> (s: String) -> String
```

Extracts a substring starting at the given index for the given length.

### find

```saga
fun find : (sub: String) -> (s: String) -> Maybe String
```

Finds the first occurrence of a substring, returning it and the rest.

### strip_prefix

```saga
fun strip_prefix : (prefix: String) -> (s: String) -> Maybe String
```

Strips a prefix from the string, returning the rest or Nothing.

### contains

```saga
fun contains : (sub: String) -> (s: String) -> Bool
```

Returns True if the string contains the substring.

### starts_with

```saga
fun starts_with : (prefix: String) -> (s: String) -> Bool
```

Returns True if the string starts with the given prefix.

### ends_with

```saga
fun ends_with : (suffix: String) -> (s: String) -> Bool
```

Returns True if the string ends with the given suffix.

### split

```saga
fun split : (sep: String) -> (s: String) -> List String
```

Splits a string by a separator into a list of parts.

### replace

```saga
fun replace : (pattern: String) -> (replacement: String) -> (s: String) -> String
```

Replaces the first occurrence of a pattern with a replacement.

### replace_all

```saga
fun replace_all : (pattern: String) -> (replacement: String) -> (s: String) -> String
```

Replaces all occurrences of a pattern with a replacement.

### join

```saga
fun join : (sep: String) -> (parts: List String) -> String
```

Joins a list of strings with a separator.

### is_alpha

```saga
fun is_alpha : (s: String) -> Bool
```

Returns True if all characters are alphabetic (a-z, A-Z).

### is_digit

```saga
fun is_digit : (s: String) -> Bool
```

Returns True if all characters are digits (0-9).

### is_alphanumeric

```saga
fun is_alphanumeric : (s: String) -> Bool
```

Returns True if all characters are alphanumeric (a-z, A-Z, 0-9).

### is_upper

```saga
fun is_upper : (s: String) -> Bool
```

Returns True if all characters are uppercase (A-Z).

### is_lower

```saga
fun is_lower : (s: String) -> Bool
```

Returns True if all characters are lowercase (a-z).

### is_whitespace

```saga
fun is_whitespace : (s: String) -> Bool
```

Returns True if all characters are whitespace.

### byte_size

```saga
fun byte_size : String -> Int
```

Returns the length of the raw bytes of the string.

### repeat

```saga
fun repeat : (n: Int) -> (s: String) -> String
```

Repeats a string n times.

### pad_left

```saga
fun pad_left : (width: Int) -> (fill: String) -> (s: String) -> String
```

Pads a string on the left to the given width using the fill string.

### pad_right

```saga
fun pad_right : (width: Int) -> (fill: String) -> (s: String) -> String
```

Pads a string on the right to the given width using the fill string.

