# Module /string

UTF-8 string utilities for case conversion, trimming, padding, searching, and slugification.

```tangu
(use /string)
```

## Functions & symbols

### byte-count-of

`(string/byte-count-of s) -> Int`

Returns the raw UTF-8 byte length of `s` in O(1) time.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | UTF-8 string |

```tangu
(string/byte-count-of "café") ; -> 5
```

### byte-slice

`(string/byte-slice s start [end]) -> String`

Slices `s` by UTF-8 byte offsets in O(1) time (verifying character boundaries).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Source UTF-8 string |
| `start` | `Int` | no | Start byte offset |
| `end` | `Int` | yes | Optional exclusive end byte offset |

```tangu
(string/byte-slice "hello" 0 4)
```

### chars

`(chars str) -> Array`

Converts string into an array of individual Unicode Char elements.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |

```tangu
(chars "tan") ; -> ['t' 'a' 'n']
```

### contains?

`(contains? str substring) -> Bool`

Returns true if str contains the given substring.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Haystack |
| `substring` | `String` | no | Needle |

```tangu
(contains? "hello world" "world") ; -> true
```

### count-of

`(string/count-of s) -> Int`

Returns the number of Unicode characters (code points) in `s`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | UTF-8 string |

```tangu
(string/count-of "café") ; -> 4
```

### ends-with?

`(ends-with? str suffix) -> Bool`

Returns true if str ends with suffix.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |
| `suffix` | `String` | no | Suffix to check |

```tangu
(ends-with? "main.tan" ".tan") ; -> true
```

### format-string

`(string/format-string template args...) -> String`

Formats a template string with positional argument substitution.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `template` | `String` | no | Template format string |
| `args` | `Any` | no | Values to format into placeholders |

```tangu
(string/format-string "Hello {}!" "Tangu")
```

### ignore-case-contains?

`(string/ignore-case-contains? str substring) -> Bool`

Returns true if str contains the given substring (case-insensitive, zero-allocation for ASCII).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Haystack |
| `substring` | `String` | no | Needle |

```tangu
(use {ignore-case-contains?} /string)
(ignore-case-contains? "TikTok.com" "tiktok.com") ; -> true
```

### ignore-case-index-of

`(string/ignore-case-index-of str sub) -> (Or Int)`

Returns 0-based character index of substring `sub` in `str` (case-insensitive), or () if not found.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Haystack |
| `sub` | `String` | no | Needle |
| `from-index` | `Int` | no | Optional 0-based start character index |

```tangu
(use {ignore-case-index-of} /string)
(ignore-case-index-of "Hello World" "world") ; -> 6
```

### index-of

`(string/index-of s needle) -> (Or Int None)`

Returns the 0-based character index of the first occurrence of `needle`, or `()` if absent.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Haystack string |
| `needle` | `String` | no | Substring to locate |

```tangu
(string/index-of "tangu.dev" ".") ; -> 5
```

### is-blank?

`(string/is-blank? x) -> Bool`

Returns true if x is (), "", or contains only whitespace characters.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `x` | `Any` | no | Value to check (String or None) |

```tangu
(use {is-blank?} /string)
(is-blank? "   ") ; -> true
```

### last-index-of

`(string/last-index-of str sub) -> (Or Int)`

Returns last 0-based character index of substring `sub` in `str` (optionally up to `end-index`), or () if not found.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Haystack |
| `sub` | `String` | no | Needle |
| `end-index` | `Int` | no | Optional 0-based end character index |

```tangu
(use {last-index-of} /string)
(last-index-of "hello world" "o") ; -> 7
```

### pad-left

`(pad-left str width) -> String`

Pads string on the left with spaces until it reaches width.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | String to pad |
| `width` | `Int` | no | Target total width |

```tangu
(pad-left "42" 5) ; -> "   42"
```

### pad-right

`(pad-right str width) -> String`

Pads string on the right with spaces until it reaches width.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | String to pad |
| `width` | `Int` | no | Target total width |

```tangu
(pad-right "42" 5) ; -> "42   "
```

### repeat

`(string/repeat s count) -> String`

Repeats `s` `count` times consecutively.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | String to repeat |
| `count` | `Int` | no | Repetition count >= 0 |

```tangu
(string/repeat "ab" 3) ; -> "ababab"
```

### replace

`(replace str from to) -> String`

Replaces all occurrences of `from` with `to` in `str`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Target string |
| `from` | `String` | no | Substring to find |
| `to` | `String` | no | Replacement string |

```tangu
(replace "foo bar" "bar" "baz") ; -> "foo baz"
```

### slice

`(slice str start) -> String`

Returns substring from start to end index. Supports negative indices and Range literals like (slice str 0..5).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |
| `start` | `Int` | no | 0-based start index (supports negative bounds) |
| `end` | `Int` | no | Optional exclusive end index |

```tangu
(slice "hello" 0 2) ; -> "he"
```

### split

`(split str delimiter) -> Array`

Splits str by separator delimiter, returning an Array of substrings.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | String to split |
| `delimiter` | `String` | no | Separator |

```tangu
(split "a,b,c" ",") ; -> ["a" "b" "c"]
```

### starts-with?

`(starts-with? str prefix) -> Bool`

Returns true if str begins with prefix.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |
| `prefix` | `String` | no | Prefix to check |

```tangu
(starts-with? "/api/users" "/api") ; -> true
```

### strip-prefix

`(string/strip-prefix s prefix) -> String`

Removes `prefix` from the start of `s` when present, leaving `s` unchanged otherwise.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Input string |
| `prefix` | `String` | no | Prefix to strip if present |

```tangu
(string/strip-prefix "/stdlib" "/") ; -> "stdlib"
```

### strip-suffix

`(string/strip-suffix s suffix) -> String`

Removes `suffix` from the end of `s` when present, leaving `s` unchanged otherwise.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `s` | `String` | no | Input string |
| `suffix` | `String` | no | Suffix to strip if present |

```tangu
(string/strip-suffix "file.tan" ".tan") ; -> "file"
```

### to-lower-case

`(to-lower-case str) -> String`

Converts all characters in string to lowercase.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |

```tangu
(to-lower-case "TANGU") ; -> "tangu"
```

### to-upper-case

`(to-upper-case str) -> String`

Converts all characters in string to uppercase.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |

```tangu
(to-upper-case "tangu") ; -> "TANGU"
```

### trim

`(trim str) -> String`

Returns a copy of the string with leading and trailing whitespace removed.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |

```tangu
(trim "  hello  ") ; -> "hello"
```

### trim-end

`(trim-end str) -> String`

Returns string with trailing whitespace removed.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |

### trim-start

`(trim-start str) -> String`

Returns string with leading whitespace removed.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `str` | `String` | no | Input string |
