2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
---
|
|
|
|
|
# Contents
|
|
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
[TOC]
|
|
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
# String Manipulation
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-17 02:07:16 -07:00
|
|
|
Global table variable: `string`
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## Description
|
2023-04-21 02:52:49 -07:00
|
|
|
|
|
|
|
|
The following methods have been added to the built-in Lua
|
2023-05-17 02:07:16 -07:00
|
|
|
[`string` table](https://www.lua.org/manual/5.3/manual.html#6.4).
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-17 02:07:16 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
# Methods
|
|
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
|
|
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.builder
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.builder <span class="paramlist">()</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.builder <span class="paramlist">(st)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
2023-05-17 02:07:16 -07:00
|
|
|
- Creates a [StringBuilder][java.lang.StringBuilder].
|
2023-04-21 02:52:49 -07:00
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">st:</span> _([string][LuaString])_ String to append on instantiation.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([StringBuilder][java.lang.StringBuilder])_ New `StringBuilder` instance.
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.endsWith
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.endsWith <span class="paramlist">(st, suffix)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Checks if a string ends with a set of characters.
|
|
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">st:</span> _([string][LuaString])_ The string to be checked.
|
|
|
|
|
- <span class="param">suffix:</span> _([string][LuaString])_ The suffix to be compared with.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([bool][LuaBoolean])_ `true` if ___suffix___ matches the end characters of ___st___.
|
2023-04-21 02:52:49 -07:00
|
|
|
- Aliases:
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.endswith</span>
|
|
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.isNumber
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.isNumber <span class="paramlist">(st)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Checks if a string contains numeric characters only.
|
|
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">st:</span> _([string][LuaString])_ The string to be checked.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([bool][LuaBoolean])_ `true` if all characters are numeric, `false` otherwise.
|
2023-04-21 02:52:49 -07:00
|
|
|
- Aliases:
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.isnumber</span>
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.isNumeric</span>
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.isnumeric</span>
|
|
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.ltrim
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.ltrim <span class="paramlist">(st)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Removes leading whitespace from a string.
|
|
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">st:</span> _([string][LuaString])_ The string to be trimmed.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([string][LuaString])_ Trimmed string.
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.rtrim
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.rtrim <span class="paramlist">(st)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Removes trailing whitespace from a string.
|
|
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">st:</span> _([string][LuaString])_ The string to be trimmed.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([string][LuaString])_ Trimmed string.
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.split
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.split <span class="paramlist">(str, delim)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Splits a string into a table.
|
|
|
|
|
- Parameters:
|
2023-05-17 02:07:16 -07:00
|
|
|
- <span class="param">str:</span> _([string][LuaString])_ The string to be split.
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">delim:</span> _([string][LuaString])_ The delimiter character(s) used to
|
|
|
|
|
split the string.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([table][LuaTable])_ List of strings.
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.startsWith
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.startsWith <span class="paramlist">(st, prefix)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Checks if a string begins with a set of characters.
|
|
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">st:</span> _([string][LuaString])_ The string to be checked.
|
|
|
|
|
- <span class="param">prefix:</span> _([string][LuaString])_ The prefix to be compared with.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([bool][LuaBoolean])_ `true` if ___prefix___ matches the beginning characters of
|
|
|
|
|
___st___.
|
2023-04-21 02:52:49 -07:00
|
|
|
- Aliases:
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.startswith</span>
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.beginsWith</span>
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.beginswith</span>
|
|
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.trim
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.trim <span class="paramlist">(st)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Removes leading & trailing whitespace from a string.
|
|
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">st:</span> _([string][LuaString])_ The string to be trimmed.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([string][LuaString])_ Trimmed string.
|
2023-04-21 02:52:49 -07:00
|
|
|
|
2023-05-16 20:13:17 -07:00
|
|
|
|
2023-04-21 02:52:49 -07:00
|
|
|
---
|
2023-05-16 20:13:17 -07:00
|
|
|
## string.valueOf
|
2023-04-21 02:52:49 -07:00
|
|
|
<div class="function">
|
2023-05-16 20:13:17 -07:00
|
|
|
string.valueOf <span class="paramlist">(obj)</span>
|
2023-04-21 02:52:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
- Retrieves string value of an object.
|
|
|
|
|
- Parameters:
|
2023-05-16 20:13:17 -07:00
|
|
|
- <span class="param">obj:</span> _([Object][java.lang.Object])_ Object instance to be
|
|
|
|
|
converted.
|
2023-05-17 02:07:16 -07:00
|
|
|
- Returns: _([string][LuaString])_ String value of object.
|
2023-04-21 02:52:49 -07:00
|
|
|
- Aliases:
|
|
|
|
|
- <span style="color:green; font-style:italic;">string.valueof</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[java.lang.StringBuilder]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/StringBuilder.html
|
|
|
|
|
[java.lang.Object]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Object.html
|
|
|
|
|
|
|
|
|
|
[LuaBoolean]: http://luaj.org/luaj/3.0/api/org/luaj/vm2/LuaBoolean.html
|
|
|
|
|
[LuaString]: http://luaj.org/luaj/3.0/api/org/luaj/vm2/LuaString.html
|
|
|
|
|
[LuaTable]: http://luaj.org/luaj/3.0/api/org/luaj/vm2/LuaTable.html
|