PowerApps 中的 Len 函数Len function in PowerApps

返回文本字符串的长度。Returns the length of a string of text.

说明Description

如果将单个字符串指定为参数,则返回值是数字形式的长度。If you specify a single string as the argument, the return value is the length as a number. 如果指定一个包含字符串的单列,则返回值是一个单列表,其中包含每个字符串的长度。If you specify a single-column table that contains strings, the return value is a single-column table that contains the length of each string. 如果你有多列表,可以将其调整为单列表,如使用表中所述。If you have a multi-column table, you can shape it into a single-column table, as working with tables describes.

如果指定字符串,则 Len 返回 0。If you specify an empty string, Len returns 0.

语法Syntax

Len( String )Len( String )

  • String - 必需。String - Required. 要度量的字符串。The string to measure.

Len( SingleColumnTable )Len( SingleColumnTable )

  • SingleColumnTable - 必需。SingleColumnTable - Required. 要计算字符串长度的单列表。A single-column table of strings to measure.

示例Examples

单个字符串Single string

对于本部分中的示例,数据源是名为“Author”的文本输入控件,其中包含字符串“E.For the examples in this section, the data source is a text-input control that's named Author and that contains the string "E. E.E. Cummings”。Cummings".

公式Formula 说明Description 结果Result
Len( Author.Text )Len( Author.Text ) 计算 Author 控件中字符串的长度。Measures the length of the string in the Author control. 1414
Len( "" )Len( "" ) 计算空字符串的长度。Measures the length of an empty string. 00

单列表Single-column table

对于本节中的第一个示例,数据源名为 People,并且包含以下数据:For the first example in this section, the data source is named People and contains this data:

公式Formula 说明Description 结果Result
Len( ShowColumns( People, "Address" ) )Len( ShowColumns( People, "Address" ) ) People 表的 Address 中:In the Address column of the People table:
  • 计算每个字符串的长度。Measures the length of each string.
  • 返回一个单列表,其中包含每个字符串的长度。Returns a single-column table that contains the length of each string.
Len( [ "Hello", "to the", "World", "" ] )Len( [ "Hello", "to the", "World", "" ] ) 在内联表的 Value 列中:In the Value column of the inline table:
  • 计算每个字符串的长度。Measures the length of each string.
  • 返回一个单列表,其中包含每个字符串的长度。Returns a single-column table that contains the length of each string.