API/text: Difference between revisions

From OpenComputers: Rebooted
Jump to navigation Jump to search
imported>OCDoc Import
Imported from legacy OpenComputers documentation at ocdoc.cil.li
 
Clean up Markdown artifacts from DokuWiki migration
 
Line 3: Line 3:
This API provides some more general operations on strings and data serialization into and back from strings.
This API provides some more general operations on strings and data serialization into and back from strings.


* `text.detab(value: string, tabWidth: number): string`
* <code>text.detab(value: string, tabWidth: number): string</code>


<pre>Converts tabs in a string to spaces, while aligning the tags at the specified tab width. This is used for formatting text in `term.write`, for example.
<pre>Converts tabs in a string to spaces, while aligning the tags at the specified tab width. This is used for formatting text in term.write, for example.
</pre>
</pre>
* `text.padRight(value: string, length: number): string`
* <code>text.padRight(value: string, length: number): string</code>


<pre>Pads a string with whitespace on the right up to the specified length.
<pre>Pads a string with whitespace on the right up to the specified length.
</pre>
</pre>
* `text.padLeft(value: string, length: number): string`
* <code>text.padLeft(value: string, length: number): string</code>


<pre>Pads a string with whitespace on the left up to the specified length.
<pre>Pads a string with whitespace on the left up to the specified length.
</pre>
</pre>
* `text.trim(value: string): string`
* <code>text.trim(value: string): string</code>


<pre>Removes whitespace characters from the start and end of a string.
<pre>Removes whitespace characters from the start and end of a string.
</pre>
</pre>
* `text.wrap(value:string, width:number, maxWidth:number)`
* <code>text.wrap(value:string, width:number, maxWidth:number)</code>


<pre>Wraps the provided string to specified width.
<pre>Wraps the provided string to specified width.
</pre>
</pre>
* `text.wrappedLines(value:string, width:number, maxWidth:number)`
* <code>text.wrappedLines(value:string, width:number, maxWidth:number)</code>


<pre>Returns a wrapper function around `text.wrap`.
<pre>Returns a wrapper function around text.wrap.
</pre>
</pre>
* `text.tokenize(value:string)`
* <code>text.tokenize(value:string)</code>


<pre>Splits the input string into a table, using space as the delimiter.
<pre>Splits the input string into a table, using space as the delimiter.
Line 34: Line 34:


{{:API/contents}}
{{:API/contents}}

Latest revision as of 20:26, 24 August 2026

Text API

This API provides some more general operations on strings and data serialization into and back from strings.

  • text.detab(value: string, tabWidth: number): string
Converts tabs in a string to spaces, while aligning the tags at the specified tab width. This is used for formatting text in term.write, for example.
  • text.padRight(value: string, length: number): string
Pads a string with whitespace on the right up to the specified length.
  • text.padLeft(value: string, length: number): string
Pads a string with whitespace on the left up to the specified length.
  • text.trim(value: string): string
Removes whitespace characters from the start and end of a string.
  • text.wrap(value:string, width:number, maxWidth:number)
Wraps the provided string to specified width.
  • text.wrappedLines(value:string, width:number, maxWidth:number)
Returns a wrapper function around text.wrap.
  • text.tokenize(value:string)
Splits the input string into a table, using space as the delimiter.

Contents

APIs
OpenOS buffer - colors - component - computer - event - filesystem - uuid - internet - keyboard - note - process - rc - robot - serialization - shell - sides - term - text - thread - transforms - unicode
Lua Libraries coroutine - package - io - os