Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
将所有字符串匹配项替换为指定字符串。
弃用的别名:replace()
若要替换多个字符串,请参阅 replace_strings()。
语法
replace_string(
发短信,查找,重写)
详细了解语法约定。
参数
| 客户 | 类型 | 必需 | 说明 |
|---|---|---|---|
| 文本 | string |
✔️ | 源字符串。 |
| 查找 | string |
✔️ | 要替换的字符串。 |
| 重写 | string |
✔️ | 替换字符串。 |
返回
在使用 rewrite 计算结果替换 lookup 的所有匹配项后返回 text。 匹配项不会重叠。
例子
替换字符串中的单词
以下示例使用 replace_string() 将单词“cat”替换为 Message 字符串中的单词“hamster”。
print Message="A magic trick can turn a cat into a dog"
| extend Outcome = replace_string(
Message, "cat", "hamster") // Lookup strings
输出
| 消息 | 结果 |
|---|---|
| 魔术可以把猫变成狗 | 魔术可以把仓鼠变成狗 |
生成和修改数字序列
以下示例创建一个表,其中列 x 包含数字从 1 到 5,递增 1。 它添加列 str,该列使用 x 函数将“Number is”与 strcat() 列值的字符串表示形式连接起来。 然后,它会添加 replaced 列,其中“was”替换 str 列中字符串中的单词“is”。
range x from 1 to 5 step 1
| extend str=strcat('Number is ', tostring(x))
| extend replaced=replace_string(str, 'is', 'was')
输出
| x | str | 替换的内容 |
|---|---|---|
| 1 | 数值为 1.000000 | 数值曾为 1.000000 |
| 2 | 数值为 2.000000 | 数值曾为 2.000000 |
| 3 | 数值为 3.000000 | 数值曾为 3.000000 |
| 4 | 数值为 4.000000 | 数值曾为 4.000000 |
| 5 | 数值为 5.000000 | 数值曾为 5.000000 |
相关内容
- 若要替换多个字符串,请参阅 replace_strings()。
- 若要基于正则表达式替换字符串,请参阅 replace_regex()。
- 若要替换一组字符,请参阅 translate()。