Module:StringBuilder/doc

< Module:StringBuilder
Revision as of 20:59, 13 April 2024 by Ricewind (talk | contribs) (Created page with "== `StringBuilder` Module Documentation == The `StringBuilder` module provides functionality to efficiently build and manipulate strings in Lua. === Constructor === '''`StringBuilder.new()`''' Creates a new `StringBuilder` object. * '''Returns:''' `StringBuilder` object. === Methods === '''`StringBuilder:append(...)`''' Appends strings or values to the `StringBuilder` buffer. * '''Parameters:''' * `...`: One or more values to append to the buffer. '''`StringB...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is the documentation page for Module:StringBuilder

`StringBuilder` Module Documentation

The `StringBuilder` module provides functionality to efficiently build and manipulate strings in Lua.

Constructor

`StringBuilder.new()`

Creates a new `StringBuilder` object.

  • Returns: `StringBuilder` object.

Methods

`StringBuilder:append(...)`

Appends strings or values to the `StringBuilder` buffer.

  • Parameters:
 * `...`: One or more values to append to the buffer.

`StringBuilder:toString()`

Converts the `StringBuilder` buffer into a concatenated string.

  • Returns: Concatenated string representation of the `StringBuilder` buffer.

Example Usage

local StringBuilder = require("StringBuilder")

-- Create a new StringBuilder object
local sb = StringBuilder.new()

-- Append strings and values to the StringBuilder buffer
sb:append("Hello, ")
sb:append("world!")
sb:append(123)

-- Convert StringBuilder buffer to a string
local result = sb:toString()

-- Output the result
print(result)  -- Output: "Hello, world!123"