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.