StendhalScripting/LuaAPI: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>AntumDeluge
arrays: clean up
imported>AntumDeluge
String Manipulation: new methods "string.isNumber" & "string.builder"
Line 262: Line 262:
The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.4 string] library.
The following methods have been added to the built-in Lua [https://www.lua.org/manual/5.3/manual.html#6.4 string] library.


* ''<span style="color:green;">string.startsWith</span>(st, prefix)''
; ''<span style="color:green;">string.startsWith</span>(st, prefix)''
** Checks if a string begins with a set of characters.
: Checks if a string begins with a set of characters.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be checked.
: '''''st:''''' The string to be checked.
** <span style="color:darkgreen; text-style=italic;">prefix:</span> The prefix to be compared with.
: '''''prefix:''''' The prefix to be compared with.
** returns: <code>true</code> if <code>prefix</code> matches the beginning characters of <code>st</code>.
: ''returns:'' <code>true</code> if <code>prefix</code> matches the beginning characters of <code>st</code>.
:; ''aliases:''
* ''<span style="color:green;">string.beginsWith</span>(st, prefix)''
:: <span style="color:green; font-style:italic;">string.beginsWith</span>
** This is just an alias for <code>string.startsWith</code>.
* ''<span style="color:green;">string.endsWith</span>(st, suffix)''
** Checks if a string ends with a set of characters.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be checked.
** <span style="color:darkgreen; text-style=italic;">suffix:</span> The suffix to be compared with.
** returns: <code>true</code> if <code>suffix</code> matches then end characters of <code>st</code>.
* ''<span style="color:green;">string.trim</span>(st)''
** Removes leading & trailing whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.
* ''<span style="color:green;">string.ltrim</span>(st)''
** Removes leading whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.
* ''<span style="color:green;">string.rtrim</span>(st)''
** Removes trailing whitespace from a string.
** <span style="color:darkgreen; text-style=italic;">st:</span> The string to be trimmed.
** returns: Trimmed string.


; ''<span style="color:green;">string.endsWith</span>(st, suffix)''
: Checks if a string ends with a set of characters.
: '''''st:''''' The string to be checked.
: '''''suffix:''''' The suffix to be compared with.
: ''returns:'' <code>true</code> if <code>suffix</code> matches then end characters of <code>st</code>.

; ''<span style="color:green;">string.isNumber</span>(st)''
: Checks if a string contains numeric characters only.
: '''''st:''''' The string to be checked.
: ''returns:'' <code>true</code> if all characters are numeric, <code>false</code> otherwise.
:; ''aliases:''
:: <span style="color:green; font-style:italic;">string.isNumeric</span>

; ''<span style="color:green;">string.trim</span>(st)''
: Removes leading & trailing whitespace from a string.
: '''''st:''''' The string to be trimmed.
: ''returns:'' Trimmed string.

; ''<span style="color:green;">string.ltrim</span>(st)''
: Removes leading whitespace from a string.
: '''''st:''''' The string to be trimmed.
: ''returns:'' Trimmed string.

; ''<span style="color:green;">string.rtrim</span>(st)''
: Removes trailing whitespace from a string.
: '''''st:''''' The string to be trimmed.
: ''returns:'' Trimmed string.

; ''<span style="color:green;">string.builder</span>(st)''
: Creates a new instance of [https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html java.lang.StringBuilder].
: '''''st:''''' (optional) String to append on instantiation.
: ''returns:'' new StringBuilder instance.


== Table Manipulation ==
== Table Manipulation ==