API/text/zh: 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:
此API提供了一些更通用化的操作,可用于处理字符串或将数据与字符串相互转化。
此API提供了一些更通用化的操作,可用于处理字符串或将数据与字符串相互转化。


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


<pre>将字符串中的tab转换为空格,数量为指定的tab宽度。一个应用实例为`term.write`,它用此函数格式化文本。 
<pre>将字符串中的tab转换为空格,数量为指定的tab宽度。一个应用实例为term.write,它用此函数格式化文本。
</pre>
</pre>


* `text.padRight(value: string, length: number): string`
* <code>text.padRight(value: string, length: number): string</code>


<pre>在字符串右侧填充空格,使其达到指定长度。
<pre>在字符串右侧填充空格,使其达到指定长度。
</pre>
</pre>


* `text.padLeft(value: string, length: number): string`
* <code>text.padLeft(value: string, length: number): string</code>


<pre>在字符串左侧填充空格,使其达到指定长度。
<pre>在字符串左侧填充空格,使其达到指定长度。
</pre>
</pre>


* `text.trim(value: string): string`
* <code>text.trim(value: string): string</code>


<pre>移除字符串头尾处的空格。
<pre>移除字符串头尾处的空格。
</pre>
</pre>


* `text.wrap(value:string, width:number, maxWidth:number)`
* <code>text.wrap(value:string, width:number, maxWidth:number)</code>


<pre>将给定的字符串按照指定宽度换行。
<pre>将给定的字符串按照指定宽度换行。
</pre>
</pre>


* `text.wrappedLines(value:string, width:number, maxWidth:number)`
* <code>text.wrappedLines(value:string, width:number, maxWidth:number)</code>


<pre>返回封装后的`text.wrap`函数。 
<pre>返回封装后的text.wrap函数。
</pre>
</pre>


* `text.tokenize(value:string)`
* <code>text.tokenize(value:string)</code>


<pre>将输入的字符串拆分为表,使用空格分隔数据。
<pre>将输入的字符串拆分为表,使用空格分隔数据。
Line 40: Line 40:


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

Latest revision as of 20:26, 24 August 2026

Text(文本) API

此API提供了一些更通用化的操作,可用于处理字符串或将数据与字符串相互转化。

  • text.detab(value: string, tabWidth: number): string
将字符串中的tab转换为空格,数量为指定的tab宽度。一个应用实例为term.write,它用此函数格式化文本。
  • text.padRight(value: string, length: number): string
在字符串右侧填充空格,使其达到指定长度。
  • text.padLeft(value: string, length: number): string
在字符串左侧填充空格,使其达到指定长度。
  • text.trim(value: string): string
移除字符串头尾处的空格。
  • text.wrap(value:string, width:number, maxWidth:number)
将给定的字符串按照指定宽度换行。
  • text.wrappedLines(value:string, width:number, maxWidth:number)
返回封装后的text.wrap函数。
  • text.tokenize(value:string)
将输入的字符串拆分为表,使用空格分隔数据。

目录

< 100% 15% 15% >
API OpenOS buffer - colors - component - computer - event - filesystem - uuid - internet - keyboard - note - process - rc - robot - serialization - shell - sides - term - text - thread - transforms - unicode
::: Lua 库 coroutine - package - io - os