utf8.insert()

类型 函数
utf8.*
返回值 字符串
修订版 发行版 2024.3703
关键字 utf8、UTF-8、Unicode、字符串、insert
参见 utf8.remove()

概述

s 中插入一个子字符串。如果指定了 idx,则在该索引处的字符前插入 substring;否则,将 substring 连接到 s 后。请注意,idx 可以为负数。

语法

utf8.insert( s, [idx,] substring )
s (必需)

字符串。源字符串。

idx (可选)

数字。插入子字符串的位置。

substring (必需)

字符串。要插入的子字符串。

示例

local utf8 = require( "plugin.utf8" )

local testStr = "♡ 你好,世界 ♡"

print( utf8.insert( testStr, 3, "UTF-8 " ) )  --> ♡ UTF-8 你好,世界 ♡