Control:GetSelection

Reads the selected text.

Syntax

Signature
Control:GetSelection() -> string

Aliases

This function has no aliases.

Parameters

This function takes no parameters.

Returns

TypeDescription
stringSelected text.

Notes

Returns the part of Text between Cursor and Anchor. Those properties use zero-based UTF-8 byte offsets. An empty selection returns an empty string. Focus is not required.

Example

Luau
local Box = Drawing.create("TextBox", {Text = "Hello"})
Box:SelectAll()
local Result = Box:GetSelection()
print(Result)