您可以使用此函数来解析查找特定部分的字符串,然后可以将其替换为您指定的新字符串。
string_replace(str, substr, newstr);
参数 | 类型 | 描述 |
---|---|---|
str | String | 要复制的字符串。 |
substr | String | 要替换的字符串中的子字符串。 |
newstr | String | 新的子字符串来替换前一个。 |
str1 = "Hello Earth";
str2 = string_replace(str1, "Earth", "World");
这将把 str2 设置为 str1,但其 "Earth" 实例替换为 "World",导致 str2 为 "Hello World"。