---
name: string
last_updated: 2026-12-04T23:21:36Z
type: library
summary: "Provides generic functions to manipulate strings."
---

# string

Provides generic functions to manipulate strings.

**Type:** library

## Description

The string library provides generic functions to manipulate strings, such as
to extract substrings or match patterns. You can access the string library by
the global [string](/docs/reference/engine/globals/string.md) library.

See
[String pattern reference](/docs/en-us/luau/strings.md#string-pattern-reference)
for details on using [string.match()](/docs/reference/engine/globals/string.md), [string.gmatch()](/docs/reference/engine/globals/string.md), and
[string.gsub()](/docs/reference/engine/globals/string.md) to find (and replace) substrings.

## Functions

### string.byte

**Signature:** `string.byte(s: string, i?: number, j?: number): int`

Returns the internal numerical codes of the characters
`s[i], s[i+1], ..., s[j]`. The default value for `i` is 1; the default
value for `j` is `i`. These indices are corrected following the same rules
of function [string.sub()](/docs/reference/engine/globals/string.md).

Numerical codes correspond to single-byte character values (`0`-`255`).
The function returns one number per character in the specified range, so
calling it on a multi-character slice yields multiple return values. If
the resolved range is empty (start index greater than end index after
adjustment), no values are returned.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to extract byte values from. |
| `i` | `number` | `1` | The starting index of the range of characters to convert. |
| `j` | `number` | `i` | The ending index of the range of characters to convert. |

**Returns:** `int` — The numerical byte values (`0`-`255`) of each character in the
specified range.

**String Byte**

Demonstrates the `string.byte` function for reading character codes.

```lua
-- Single character
print(string.byte("A")) --> 65

-- Range of characters
print(string.byte("hello", 1, 3)) --> 104 101 108

-- Negative indices count from the end
print(string.byte("abc", -1)) --> 99

-- An empty range returns no values
print(select("#", string.byte("abc", 3, 1))) --> 0

-- Roundtrip with string.char
local a, b, c = string.byte("ABC", 1, 3)
print(string.char(a, b, c)) --> ABC
```

### string.char

**Signature:** `string.char(...: int): string`

Receives zero or more integers and returns a string with length equal to
the number of arguments, in which each character has the internal
numerical code equal to its corresponding argument.

Each integer must be in the range `[0, 255]`; values outside that range
raise an error. This is the inverse of [string.byte()](/docs/reference/engine/globals/string.md).

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `...` | `int` |  | Zero or more integers in the range `[0, 255]`, each representing a byte value. |

**Returns:** `string` — A string whose length equals the number of arguments, with each byte
set to the corresponding integer value.

**String Char**

Demonstrates the `string.char` function for building strings from byte values.

```lua
print(string.char(72, 101, 108, 108, 111)) --> Hello
print(string.char(65)) --> A

-- Zero arguments produce an empty string; byte 0 is still one character
print(#string.char()) --> 0
print(#string.char(0)) --> 1

-- Values outside 0-255 raise an error
local ok = pcall(string.char, 256)
print(ok) --> false

-- Roundtrip with string.byte
print(string.char(string.byte("Z"))) --> Z
```

### string.find

**Signature:** `string.find(s: string, pattern: string, init?: number, plain?: bool): number, number`

Searches for the first occurrence of a pattern in a string and returns the
start and end indices of the match. If no match is found, it returns
`nil.` You can specify where to start the search using the optional `init`
parameter which defaults to `1` and can be negative. An optional `plain`
parameter turns off pattern matching, so the function performs a plain
substring search; note that if you use `plain`, you must also provide
`init.`

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to search within. |
| `pattern` | `string` |  | The pattern to search for in given string. |
| `init` | `number` | `1` | The starting index for the search. |
| `plain` | `bool` | `false` | If true, turns off pattern matching and performs a plain substring search. |

**Returns:** `number`, `number` — The starting index of the match. The ending index of the match.

**String Find**

Demonstrates the `string.find` function for locating patterns and plain
substrings.

```lua
local text = "Hello, world! Hello, Roblox!"

-- Basic usage returns the start and end indices
print(string.find(text, "world")) --> 8 12

-- init starts the search later in the string
print(string.find(text, "Hello", 10)) --> 15 19

-- plain = true turns off pattern matching, so "(Hello)" is matched literally
local literal = "Hello, world! (Hello)"
print(string.find(literal, "(Hello)", 1, true)) --> 15 21

-- No match returns nil
print(string.find(text, "Studio")) --> nil
```

### string.format

**Signature:** `string.format(formatstring: string, ...: string): string`

Returns a formatted version of its variable number of arguments following
the description given in its first argument, which must be a string.

You can convert variables into user-friendly strings of text using the
[string.format()](/docs/reference/engine/globals/string.md) function. The function requires the following
format:

`%[flags][width].[precision][specifier]`.

#### Specifiers

The most important part of string formatting is the **specifiers**.

| Specifier | Accepts | Outputs | Example Output |
| --- | --- | --- | --- |
| `c` | integer |  | `3` |
| `d` or `i` | integer | Decimal representation. | `321` |
| `e` or `E` | float | Scientific notation using `e` or `E`. | `3.296e2`
`3.296E2` |
| `f` | float |  | `3231.1231` |
| `g` or `G` | float | The shorter of `e`/`E` and `f`. | `3E14`
`3e14` |
| `o` | integer | Octal representation. | `610` |
| `q` | string | String in a form suitable to be safely read back by the Luau interpreter. The string is written between double quotes and all double quotes, new lines, embedded zeros, and backslashes are correctly escaped. | `"print(\"Hi\")"` |
| `s` | string |  | `Hello world!` |
| `u` | integer | Decimal representation. | `3131` |
| `x` or `X` | integer | Hexadecimal representation. | `7fa`
`7FA` |
| `*` | any | Equivalent to `s` but accepts any variable by converting it to a string using [LuaGlobals.tostring()](/docs/reference/engine/globals/LuaGlobals.md). | `table: 0x0123456789abcdef` |
| `%` |  | `%` followed by another `%` will return the `%` sign itself. | `%` |

#### Flags

| Flag | Description |
| --- | --- |
| `-` | Left-justify the given field width (see **Width** below). Right justification is the default. |
| `+` | Forces a `+` sign to precede a number. Has no effect on negative numbers. |
| (space) | One blank space is inserted before a positive number, while negative numbers are unaffected. This is useful for making positive and negative numbers vertically align in a visual stacked list. |
| `#` | When used with `o` and `x`/`X`, writes a `0` (octal) or `0x`/`0X` (hex) before values other than zero.
When used with `e`/`E` and `f`, forces the output to contain a decimal point, even if no digits would follow (by default, no decimal point is written if no digits follow).
When used with `g` or `G`, the result is the same as with `e` or `E` but trailing zeros are not removed. |
| `0` | Left-pads the number with zeros instead of empty spaces (see **Width** below). |

#### Width

| Width | Description |
| --- | --- |
| (number) | Minimum number of characters to return. If the number of characters to be formatted is less than this number, the result is padded with blank spaces. |

#### Precision

The default precision is <code>1</code>. If you give a period without a
value, the default is <code>0</code>.

| Precision | Description |
| --- | --- |
| `.`(number) | For integer specifiers (`d`, `i`, `o`, `u`, `x`/`X`), precision specifies the minimum number of digits to be returned. If the value to be formatted is shorter than this number, the result is padded with leading zeros. A precision of `0` means that no character is written for the value `0`.
For `e`/`E` and `f` specifiers, this is the number of digits to be printed after the decimal point.
For `g`/`G` specifiers, this is the maximum number of digits (before the `e`/`E`, if present).
For `s`, this is the maximum number of characters to be returned.
For `c` and `q`, this has no effect. |

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `formatstring` | `string` |  | A string containing format specifiers that control how subsequent arguments are formatted. |
| `...` | `string` |  | Values to be formatted according to the specifiers in the format string. |

**Returns:** `string` — The format string with each specifier replaced by the formatted
representation of the corresponding argument.

**String Format**

Demonstrates the `string.format` function with specifiers, flags, width and
precision.

```lua
-- Specifiers
print(string.format("The magic word is %s", "Roblox")) --> The magic word is Roblox
print(string.format("The magic word is %q", "Roblox")) --> The magic word is "Roblox"
print(string.format("%q", 'print("Hi")')) --> "print(\"Hi\")"
print(string.format("%d in hex is %x, in octal is %o", 2042, 2042, 2042)) --> 2042 in hex is 7fa, in octal is 3772
print(string.format("%e", 329.6)) --> 3.296000e+02
print(string.format("%g", 3e14)) --> 3e+14

-- Flags
print(string.format("%-10d", 300) .. "]") --> 300       ]
print(string.format("%+i versus %+i", 300, -300)) --> +300 versus -300
print(string.format("There is a% i%% chance of rain today.", 100)) --> There is a 100% chance of rain today.
print(string.format("%#x", 255)) --> 0xff

-- Width pads with spaces, or zeros with the 0 flag
print("Score: " .. string.format("%012i", 15000)) --> Score: 000000015000

-- Precision
print(string.format("$%.2f", 300)) --> $300.00
print(string.format("%.6s", "Robloxian")) --> Roblox
print(string.format("%.8f", math.pi)) --> 3.14159265

-- Without the matching specifier, extra arguments are ignored
local template = "Skip to \na new line"
print(string.format(template, "%q")) --> Skip to
                                     --> a new line
```

### string.gmatch

**Signature:** `string.gmatch(s: string, pattern: string): function`

Returns an iterator function that, each time it is called, returns the
next captures from `pattern` over the string `s`. If the pattern has no
captures, the whole match is returned on each call.

The iterator is typically used in a generic `for` loop. When the pattern
contains capture groups, each call returns the captured substrings as
separate values. An empty match (zero-width) advances past the current
position by one character to avoid an infinite loop.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to search for pattern matches. |
| `pattern` | `string` |  | The pattern to match repeatedly against the string. |

**Returns:** `function` — An iterator function that returns the next match (or captures) each
time it is called.

**String Gmatch**

Demonstrates the `string.gmatch` function for iterating over pattern matches.

```lua
-- Iterate over all words in a sentence
for word in string.gmatch("Hello Roblox world", "%a+") do
	print(word)
end
--> Hello
--> Roblox
--> world

-- Captures are returned as separate values
local settings = {}
for key, value in string.gmatch("name=Roblox, version=1.0", "(%w+)=(%w[%w.]*)") do
	settings[key] = value
end
print(settings.name, settings.version) --> Roblox 1.0

-- Collect all numbers
local numbers = {}
for digits in string.gmatch("abc123def456", "%d+") do
	table.insert(numbers, digits)
end
print(table.concat(numbers, ", ")) --> 123, 456
```

### string.gsub

**Signature:** `string.gsub(s: string, pattern: string, replacement: Variant, n: number): string, number`

Short for global substitution. Returns a copy of `s` in which all (or the
first `n`, if given) occurrences of the pattern are substituted (replaced)
with the given `replacement`. The second value returned is the total
number of substitutions made.

The `replacement` can be one of several types, each used differently to
determine the actual string:

- string: The pattern is replaced with the string directly
- table: The string that matched the pattern is looked up in the table as
  a key, and the value (string) is what replaces it, if it exists.
- function: Called with the string that matched the pattern, should return
  the string to replace the matched pattern.

An optional final argument can be provided which specifies the maximum
number of substitutions to make (for example, stop after 2 replacements)

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string whose occurrences of the given pattern shall be replaced. |
| `pattern` | `string` |  | The pattern to be matched and replaced. |
| `replacement` | `Variant` |  | Determines what should replace the occurrence(s) of the given pattern. |
| `n` | `number` |  | The maximum number of substitutions to make. If omitted, every occurrence is replaced. |

**Returns:** `string`, `number` — A copy of `s` with pattern occurrences replaced. The total number of substitutions made.

**String Gsub**

Demonstrates the `string.gsub` function with string, table and function
replacements.

```lua
-- Basic replacement; the second value is the substitution count
print(string.gsub("I love tacos!", "tacos", "Roblox")) --> I love Roblox! 1

-- Replacement with a pattern
print(string.gsub("I like red!", "%w+", "word")) --> word word word! 3

-- Replacement table
print(string.gsub("I play Roblox.", "%w+", {I = "Je", play = "joue à"})) --> Je joue à Roblox. 3

-- Replacement function
print(string.gsub("I have 2 cats.", "%d+", function(n)
	return (tonumber(n) or 0) * 12
end)) --> I have 24 cats. 1

-- Replace only twice
print(string.gsub("aaa", "a", "b", 2)) --> bba 2

-- Capture groups (maximum of nine)
print(string.gsub("love2play Roblox", "(%w+)(%d+)(%w+)%s+(%w+)", "I %1 %2 %3 %4!")) --> I love 2 play Roblox! 1
```

### string.len

**Signature:** `string.len(s: string): int`

Returns the number of bytes in the string `s`. Because Luau strings are
byte sequences, this counts bytes rather than Unicode characters or
grapheme clusters. An empty string returns `0`. Embedded null bytes (`\0`)
are included in the count.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to measure. |

**Returns:** `int` — The number of bytes in the string.

**String Len**

Demonstrates the `string.len` function for measuring a string in bytes.

```lua
print(string.len("Hello")) --> 5
print(string.len("")) --> 0

-- Embedded null bytes are counted
print(string.len("ab\0cd")) --> 5

-- Bytes, not characters
print(string.len("é")) --> 2

-- Equivalent to the # length operator
local name = "Roblox"
print(string.len(name) == #name) --> true
```

### string.lower

**Signature:** `string.lower(s: string): string`

Returns a copy of the string `s` with all uppercase ASCII letters
(`A`-`Z`) changed to their lowercase equivalents (`a`-`z`). Characters
outside the ASCII letter range, including accented or multibyte
characters, are left unchanged.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to convert to lowercase. |

**Returns:** `string` — A copy of the string with all uppercase ASCII letters changed to
lowercase.

**String Lower**

Demonstrates the `string.lower` function for converting ASCII letters to
lowercase.

```lua
print(string.lower("HELLO")) --> hello
print(string.lower("Hello World!")) --> hello world!

-- Non-letter characters are unaffected
print(string.lower("Roblox 123!")) --> roblox 123!

-- Only ASCII letters are converted
print(string.lower("É") == "É") --> true
```

### string.match

**Signature:** `string.match(s: string, pattern: string, init?: number): string`

Looks for the first match of `pattern` in the string `s`. If the pattern
contains captures, the captured substrings are returned as separate
values; otherwise, the whole match is returned. If no match is found, the
function returns `nil`.

The optional third argument `init` specifies the byte position to start
the search (default `1`). A negative `init` counts from the end of the
string. Unlike [string.find()](/docs/reference/engine/globals/string.md), this function returns captured
values directly rather than the match indices.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to search for a pattern match. |
| `pattern` | `string` |  | The pattern to match against the string. |
| `init` | `number` | `1` | The byte position at which to start searching. |

**Returns:** `string` — The captured substrings if the pattern contains captures, or the whole
match otherwise; `nil` if no match is found.

**String Match**

Demonstrates the `string.match` function for extracting captures from a
string.

```lua
-- Extract the matched substring
print(string.match("I have 42 cats", "%d+")) --> 42

-- Multiple captures are returned as separate values
local year, month, day = string.match("2024-03-15", "(%d+)-(%d+)-(%d+)")
print(year, month, day) --> 2024 03 15

-- No match returns nil
print(string.match("hello", "%d+")) --> nil

-- init skips ahead
print(string.match("foo123bar456", "%d+", 7)) --> 456

-- Anchored pattern
print(string.match("hello", "^%a+")) --> hello
```

### string.pack

**Signature:** `string.pack(format: string, ...: Variant): string`

Returns a binary string containing the provided arguments. The first
argument, `format`, determines the way the remaining arguments are packed;
see [here](https://www.lua.org/manual/5.3/manual.html#6.4.2) for options.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `format` | `string` |  | A format string that describes the layout and types of the values to pack. |
| `...` | `Variant` |  | The values to serialize into binary form according to the format string. |

**Returns:** `string` — A binary string containing the arguments packed according to the
format string.

**String Pack**

Demonstrates the `string.pack` function for serializing values into a binary
string.

```lua
-- "<" selects little-endian; "i4" is a 4-byte signed integer
local packed = string.pack("<i4", 1000)
print(#packed) --> 4
print(string.byte(packed, 1, 4)) --> 232 3 0 0

-- Several values with one format: a byte, a 2-byte integer and a zero-terminated string
local record = string.pack("<BI2z", 7, 513, "hi")
print(#record) --> 6
```

### string.packsize

**Signature:** `string.packsize(format: string): number`

Returns the size in bytes of any string packed with a given description.
The sole argument, `format`, determines the way the remaining arguments
are packed, but you cannot use `s` and `z` because they have variable
lengths. See [here](https://www.lua.org/manual/5.3/manual.html#6.4.2) for
options.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `format` | `string` |  | A format string describing the packing layout (must not contain variable-length options `s` or `z`). |

**Returns:** `number` — The total number of bytes that a string packed with the given format
would occupy.

**String Packsize**

Demonstrates the `string.packsize` function for computing the size of a packed
format.

```lua
print(string.packsize("<i4")) --> 4
print(string.packsize("<i4i2")) --> 6
print(string.packsize("<BI2d")) --> 11

-- Variable-length options (s and z) are not allowed
local ok = pcall(string.packsize, "z")
print(ok) --> false

-- The size matches what pack produces
print(#string.pack("<i4i2", 1, 2) == string.packsize("<i4i2")) --> true
```

### string.rep

**Signature:** `string.rep(s: string, n: int): string`

Returns a string that is the concatenation of `n` copies of the string
`s`. If `n` is zero or negative, the function returns an empty string. An
error is raised if the resulting string would exceed the maximum string
size.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to repeat. |
| `n` | `int` |  | The number of times to repeat the string. |

**Returns:** `string` — A string formed by concatenating `n` copies of `s`, or an empty string
if `n` is zero or negative.

**String Rep**

Demonstrates the `string.rep` function for repeating a string.

```lua
print(string.rep("ab", 3)) --> ababab
print(string.rep("Go! ", 2) .. "|") --> Go! Go! |

-- Zero or negative repeats return an empty string
print(#string.rep("x", 0)) --> 0
print(#string.rep("x", -1)) --> 0

-- Useful for padding or separators
local separator = string.rep("-", 20)
print(separator) --> --------------------
```

### string.reverse

**Signature:** `string.reverse(s: string): string`

Returns a string that is the string `s` reversed byte-by-byte. Because the
reversal operates on individual bytes, multibyte UTF-8 sequences are not
preserved as valid characters after reversal.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to reverse. |

**Returns:** `string` — A new string with the bytes of `s` in reverse order.

**String Reverse**

Demonstrates the `string.reverse` function for reversing a string byte by
byte.

```lua
print(string.reverse("hello")) --> olleh
print(string.reverse("Roblox")) --> xolboR
print(string.reverse("a")) --> a
print(#string.reverse("")) --> 0

-- Palindrome check
local function isPalindrome(text)
	local lower = string.lower(text)
	return lower == string.reverse(lower)
end
print(isPalindrome("racecar")) --> true
print(isPalindrome("hello")) --> false
```

### string.split

**Signature:** `string.split(s: string, separator?: string): table`

Splits a string into parts based on the defined separator character(s),
returning a table of ordered results.

If an empty "slice" is located, that part will be returned as an empty
string. For instance `string.split("abc||def", "|")` will return a table
with three strings: `"abc"`, `""`, and `"def"`.

Also note that whitespace from the original string will be preserved, for
example `string.split("abc _ def", "_")` will honor the whitespace on both
sides of the `_` separator. By default, the separator character is `,` but
you can specify an alternative character or series of characters.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to split. |
| `separator` | `string` | `,` | The separator character(s) to be used for splitting the string. |

**Returns:** `table` — A table of substrings produced by splitting `s` at each occurrence of
the separator.

**String Split**

Demonstrates the `string.split` function for splitting a string into a table
of parts.

```lua
local values = string.split("a,b,c", ",")
print(values[1], values[2], values[3]) --> a b c

-- The method form works too, and the default separator is ","
print(#("x,y"):split()) --> 2

-- Empty slices are kept as empty strings
local parts = string.split("foo,,bar", ",")
print(#parts, parts[2] == "") --> 3 true
print(#string.split(",,", ",")) --> 3

-- An empty input returns a single empty string
local empty = string.split("", ",")
print(#empty, empty[1] == "") --> 1 true

-- Whitespace is preserved
print(string.split("foo , bar", ",")[1] == "foo ") --> true

-- Separators can be several characters, including non-ASCII ones
local words = string.split("hello•world", "•")
print(words[1], words[2]) --> hello world
```

### string.sub

**Signature:** `string.sub(s: string, i?: int, j?: int): string`

Returns the substring of `s` that starts at byte position `i` and
continues until and including byte position `j`. Both `i` and `j` can be
negative: `-1` refers to the last byte, `-2` to the second-to-last, and so
on. The default for `i` is `1` (the beginning) and `j` defaults to `-1`
(the end).

If the resolved `i` is less than `1`, it is corrected to `1`. If `j`
exceeds the string length, it is corrected to the string length. If after
these corrections `i` is greater than `j`, the function returns an empty
string.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The source string to extract a substring from. |
| `i` | `int` | `1` | The starting byte position of the substring (negative values count from the end). |
| `j` | `int` | `-1` | The ending byte position of the substring, inclusive (negative values count from the end). |

**Returns:** `string` — The substring from position `i` to `j` inclusive, or an empty string
if the range is empty.

**String Sub**

Demonstrates the `string.sub` function for extracting substrings by byte
position.

```lua
local text = "Hello, world!"
print(string.sub(text, 1, 5)) --> Hello
print(string.sub(text, 8)) --> world!
print(string.sub(text, -6)) --> world!
print(string.sub(text, -6, -2)) --> world

-- Extract a file extension
local filename = "script.lua"
local dot = string.find(filename, "%.")
print(string.sub(filename, dot + 1)) --> lua

-- Out-of-range values are corrected; an empty range returns an empty string
print(string.sub("abc", 0, 10)) --> abc
print(#string.sub("abc", 3, 1)) --> 0
```

### string.unpack

**Signature:** `string.unpack(format: string, data: string, readStart?: number): Tuple`

Extracts the values packed in the provided binary string based on the
first argument, `format`, which should match the one originally used to
[pack()](/docs/reference/engine/globals/string.md) the string; see
[here](https://www.lua.org/manual/5.3/manual.html#6.4.2) for options. The
optional third parameter determines the byte at which the reading starts.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `format` | `string` |  | The format string that describes how the binary data was packed. |
| `data` | `string` |  | The binary string to unpack values from. |
| `readStart` | `number` | `1` | The byte position in `data` at which to begin reading. |

**Returns:** `Tuple` — The values packed into the provided binary string, plus the index of
the first unread byte.

**String Unpack**

Demonstrates the `string.unpack` function for reading values back out of a
binary string.

```lua
local packed = string.pack("<i4z", 1000, "hi")

-- Returns each value, followed by the index of the first unread byte
local number, text, nextIndex = string.unpack("<i4z", packed)
print(number, text, nextIndex) --> 1000 hi 8

-- The third argument chooses where reading starts
local second, after = string.unpack("z", packed, 5)
print(second, after) --> hi 8
```

### string.upper

**Signature:** `string.upper(s: string): string`

Returns a copy of the string `s` with all lowercase ASCII letters
(`a`-`z`) changed to their uppercase equivalents (`A`-`Z`). Characters
outside the ASCII letter range, including accented or multibyte
characters, are left unchanged.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `s` | `string` |  | The string to convert to uppercase. |

**Returns:** `string` — A copy of the string with all lowercase ASCII letters changed to
uppercase.

**String Upper**

Demonstrates the `string.upper` function for converting ASCII letters to
uppercase.

```lua
print(string.upper("hello")) --> HELLO
print(string.upper("Hello World!")) --> HELLO WORLD!

-- Non-letter characters are unaffected
print(string.upper("roblox 123!")) --> ROBLOX 123!

-- Only ASCII letters are converted
print(string.upper("é") == "é") --> true
```