WPS 加载项开发 > 表格 API 参考 > WorksheetFunction > 方法 > WorksheetFunction.Replace 方法
根据指定的字符数,将文本字符串的部分用其他文本字符串替换。

语法

表达式.Replace(Arg1, Arg2, Arg3, Arg4)

表达式   一个代表 WorksheetFunction 对象的变量。

参数

名称 必选/可选 数据类型 说明
Arg1 必选 String 要替换其中某些字符的文本。
Arg2 必选 Double 在 Arg1 中用 Arg4 替换的字符的位置。
Arg3 必选 Double 在 Arg1 中使用 Replace 方法替换为 Arg4 的字符个数。
Arg4 必选 String 用以替换 Arg1 中字符的文本。

返回值
一个字符串值,表示替换之后的新字符串。

示例

此示例用“ac-ef”替换“abcdef”,并在该过程中通知用户。

示例代码
function ReturnURL(){
    let strCurrent = "abcdef"

    // Notify user and display current string.
    MsgBox("The current string is: " + strCurrent)

    // Replace "cd" with "-".
    let strReplaced = Application.WorksheetFunction.Replace(strCurrent, 3, 2, "-")

    // Notify user and display replaced string.
    MsgBox("The replaced string is: " + strReplaced)
}


请参阅