PowerApps 中的 Replace 和 Substitute 函数Replace and Substitute functions in PowerApps

将文本字符串的一部分替换为其他字符串。Replace a portion of a string of text with another string.

说明Description

Replace 函数按起始位置和长度标识要替换的文本。The Replace function identifies the text to replace by starting position and length.

Substitute 函数通过匹配字符串标识要替换的文本。The Substitute function identifies the text to replace by matching a string. 如果找到多个匹配项,可以控制要替换哪一个。If more than one match is found, you can control which one is replaced.

如果传递单个字符串,则返回值为修改后的字符串。If you pass a single string, the return value is the modified string. 如果传递包含字符串的单列,则返回值为修改后字符串的单列表。If you pass a single-column table that contains strings, the return value is a single-column table of modified strings. 如果你有多列表,可以将其调整为单列表,如使用表中所述。If you have a multi-column table, you can shape it into a single-column table, as working with tables describes.

语法Syntax

Replace( String, StartingPosition, NumberOfCharacters, NewString )Replace( String, StartingPosition, NumberOfCharacters, NewString )

  • String - 必需。String - Required. 要运算的字符串。The string to operate on.
  • StartingPosition - 必需。StartingPosition - Required. 开始替换的字符位置。Character position to start the replacement. String 的第一个字符位于位置 1。The first character of String is at position 1.
  • NumberOfCharacters - 必需。NumberOfCharacters - Required. String 中要替换的字符数。The number of characters to replace in String.
  • NewString - 必需。NewString - Required. 替换字符串。The replacement string. 此参数中的字符数可能与 NumberOfCharacters 参数中的字符数不同。The number of characters in this argument can differ from the NumberOfCharacters argument.

Substitute( String, OldString, NewString [, InstanceNumber ] )Substitute( String, OldString, NewString [, InstanceNumber ] )

  • String - 必需。String - Required. 要运算的字符串。The string to operate on.
  • OldString - 必需。OldString - Required. 要替换的字符串。The string to replace.
  • NewString - 必需。NewString - Required. 替换字符串。The replacement string. OldStringNewString 可以有不同长度。OldString and NewString can have different lengths.
  • InstanceNumber - 可选。InstanceNumber - Optional. 默认情况下将替换 OldString 的第一个实例。By default, the first instance of OldString is replaced. 如果 String 包含多个实例,则可以指定要替换哪个实例。If String contains more than one instance, you can specify which instance to replace.

Replace( SingleColumnTable, StartingPosition, NumberOfCharacters, NewString )Replace( SingleColumnTable, StartingPosition, NumberOfCharacters, NewString )

  • SingleColumnTable - 必需。SingleColumnTable - Required. 要运算的字符串的单列表。A single-column table of strings to operate on.
  • StartingPosition - 必需。StartingPosition - Required. 开始替换的字符位置。Character position to start the replacement. 表中每个字符串的第一个字符位于位置 1。The first character of each string in the table is at position 1.
  • NumberOfCharacters - 必需。NumberOfCharacters - Required. 每个字符串中要替换的字符数。The number of characters to replace in each string.
  • NewString - 必需。NewString - Required. 替换字符串。The replacement string. 此参数中的字符数可能与 NumberOfCharacters 参数中的字符数不同。The number of characters in this argument can differ from the NumberOfCharacters argument.

Substitute( SingleColumnTable, OldString, NewString [, InstanceNumber ] )Substitute( SingleColumnTable, OldString, NewString [, InstanceNumber ] )

  • SingleColumnTable - 必需。SingleColumnTable - Required. 要运算的字符串的单列表。A single-column table of strings to operate on.
  • OldString - 必需。OldString - Required. 要替换的字符串。The string to replace.
  • NewString - 必需。NewString - Required. 替换字符串。The replacement string. OldStringNewString 可以有不同长度。OldString and NewString can have different lengths.
  • InstanceNumber - 可选。InstanceNumber - Optional. 默认情况下将替换 OldString 的第一个实例。By default, the first instance of OldString is replaced. 如果表包含多个实例,则可以指定要替换哪个实例。If the table contains more than one instance, you can specify which instance to replace.