PowerApps 中的 Left、Mid 與 Right 函式Left, Mid, and Right functions in PowerApps

擷取文字字串的左邊、中間或右邊部分。Extracts the left, middle, or right portion of a string of text.

說明Description

LeftMidRight 函式會傳回字串的一部分。The Left, Mid, and Right functions return a portion of a string.

  • Left 會傳回字串前端的字元。Left returns the beginning characters of a string.
  • Mid 會傳回字串中間的字元。Mid returns the middle characters of a string.
  • Right 會傳回字串尾端的字元。Right returns the ending characters of a string.

如果您指定單一字串作為引數,函式會傳回字串中您所要求的部分。If you specify a single string as an argument, the function returns the portion that you requested of the string. 如果您指定包含字串的單欄資料表,函式會傳回這些字串中您所要求之部分的單欄資料表。If you specify a single-column table that contains strings, the function returns a single-column table of the portions that you requested of those strings. 如果您指定多欄資料表,您可依照使用資料表所述,將該資料表改為單欄資料表。If you specify a multi-column table, you can shape it into a single-column table, as working with tables describes.

如果開始位置是負數或超出字串結尾,Mid 會傳回「空白」。If the starting position is negative or beyond the end of the string, Mid returns blank. 您可以使用 Len 函式來檢查字串的長度。You can check the length of a string by using the Len function. 如果您要求的字元數超過字串所含的字元數,函式會傳回其最多能傳回的字元數。If you request more characters than the string contains, the function returns as many characters as possible.

語法Syntax

Left( String, NumberOfCharacters )Left( String, NumberOfCharacters )
Mid( String, StartingPosition, NumberOfCharacters )Mid( String, StartingPosition, NumberOfCharacters )
Right( String, NumberOfCharacters )Right( String, NumberOfCharacters )

  • String - 必要項目。String - Required. 要從中擷取結果的字串。The string to from which to extract the result.
  • StartingPosition - 必要項目 (僅限 Mid)。StartingPosition - Required (Mid only). 開始位置。The starting position. 字串的第一個字元是位置 1。The first character of the string is position 1.
  • NumberOfCharacters - 必要項目。NumberOfCharacters - Required. 要傳回的字元數。The number of characters to return.

Left( SingleColumnTable, NumberOfCharacters )Left( SingleColumnTable, NumberOfCharacters )
Mid( SingleColumnTable, StartingPosition, NumberOfCharacters )Mid( SingleColumnTable, StartingPosition, NumberOfCharacters )
Right( SingleColumnTable, NumberOfCharacters )Right( SingleColumnTable, NumberOfCharacters )

  • SingleColumnTable - 必要項目。SingleColumnTable - Required. 要從中擷取結果之字串的單欄資料表。A single-column table of strings from which to extract the results.
  • StartingPosition - 必要項目 (僅限 Mid)。StartingPosition - Required (Mid only). 開始位置。The starting position. 字串的第一個字元是位置 1。The first character of the string is position 1.
  • NumberOfCharacters - 必要項目。NumberOfCharacters - Required. 要傳回的字元數。The number of characters to return.

範例Examples

單一字串Single string

本節中的範例會使用文字輸入控制項作為其資料來源The examples in this section use a text-input control as their data source. 該控制項的名稱為 Author,並包含字串 "E.The control is named Author and contains the string "E. E。E. Cummings"。Cummings".

公式Formula 說明Description 結果Result
Left( Author.Text, 5 )Left( Author.Text, 5 ) 從字串開頭擷取最多五個字元。Extracts up to five characters from the start of the string. "E."E. E."E."
Mid( Author.Text, 7, 4 )Mid( Author.Text, 7, 4 ) 從字串擷取最多四個字元,以第七個字元作為起點。Extracts up to four characters, starting with the seventh character, from the string. "Cumm""Cumm"
Right( Author.Text, 5 )Right( Author.Text, 5 ) 從字串結尾擷取最多五個字元。Extracts up to five characters from the end of the string. "mings""mings"

單欄資料表Single-column table

本節中的每個範例都會從這個名為 People 之資料來源的 Address 資料行 中擷取字串,並傳回包含結果的單欄資料表︰Each example in this section extracts strings from the Address column of this data source, named People, and returns a single-column table that contains the results:

公式Formula 說明Description 結果Result
Left( ShowColumns( People, "Address" ), 8 )Left( ShowColumns( People, "Address" ), 8 ) 擷取每個字串的前八個字元。Extracts the first eight characters of each string.
Mid( ShowColumns( People, "Address" ), 5, 7 )Mid( ShowColumns( People, "Address" ), 5, 7 ) 擷取每個字串中間的七個字元,以第五個字元作為起點。Extracts the middle seven characters of each string, starting with the fifth character.
Right( ShowColumns( People, "Address" ), 7 )Right( ShowColumns( People, "Address" ), 7 ) 擷取每個字串的最後七個字元。Extracts the last seven characters of each string.

逐步說明範例Step-by-step example

  1. 匯入或建立名為 Inventory集合,並將其顯示在資源庫中,如在資源庫中顯示影像和文字中的第一個程序所述。Import or create a collection named Inventory, and show it in a gallery, as the first procedure in Show images and text in a gallery describes.
  2. 將資源庫內下方標籤的 Text 屬性設定為下列函式:Set the Text property of the lower label in the gallery to this function:

    Right(ThisItem.ProductName, 3)Right(ThisItem.ProductName, 3)

    此標籤會顯示每個產品名稱的最後三個字元。The label shows the last three characters of each product name.