Apps
最新
False
横幅背景图像
Apps 用户指南
上次更新日期 2024年4月26日

实用的 VB 函数

此页面包含构建应用程序时可能有用的 VB 表达式。

我们在公共应用程序中将其中几个功能分组,因此您可以试用它们并查看它们的行为。

VB 函数:Where

Where() 函数返回一个从零开始的数组,其中包含基于指定筛选条件的字符串数组的子集。
假设您将一个名为 words 的变量定义为 List(Of String) = {"apple", "banana", "cherry", "date"}
要获取包含字母“a”的单词列表,请应用 Where() 函数,如下所示:
words.Where(Function(w) w.Contains("a")).ToList()words.Where(Function(w) w.Contains("a")).ToList()
输出为 {"apple", "banana", "date"}

VB 函数:Select

Select() 函数将创建一个新数组,其中包含将 Lambda 表达式应用于源数组中的每个元素的结果。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取数字乘以自身的列表,请应用 Select() 函数,如下所示:
numbers.Select(Function(n) n * n).ToArray()numbers.Select(Function(n) n * n).ToArray()
输出为 {1, 4, 9, 16, 25}

VB 函数:Aggregate

Aggregate() 函数对数组中的所有元素执行计算并返回单个值。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取数组中所有数字的总和,请应用 Aggregate() 函数,如下所示:
Dim sum = numbers.Aggregate(Function(acc, n) acc + n)Dim sum = numbers.Aggregate(Function(acc, n) acc + n)
输出为 15

VB 函数:Group By

GroupBy() 函数通过键选取器函数对序列中的元素进行分组。
假设您将一个名为 words 的变量定义为 String() = {"apple", "banana", "cherry", "date"}
要按第一个字母(即键选取器函数)对单词进行分组,请应用 GroupBy() 函数,如下所示:
words.GroupBy(Function(w) w(0))words.GroupBy(Function(w) w(0))
输出为 { {"a", "apple", "date"}, {"b", "banana"}, {"c", "cherry"} }

VB 函数:Order By

OrderBy()OrderByDescending() 函数根据键选取器函数对序列中的元素进行排序。
假设您将一个名为 words 的变量定义为 String() = {"apple", "banana", "cherry", "date"}
要按词长(即键选取器函数)对单词进行排序,请应用 OrderBy() 函数,如下所示:
words.OrderBy(Function(w) w.Length).ToArray()words.OrderBy(Function(w) w.Length).ToArray()
输出为 {"date", "apple", "cherry", "banana"}

VB 函数:Join

Join() 函数根据键选取器函数合并两个序列中的元素。

假设您有两个变量:

  • names 定义为 String() = {"John", "Jane", "Joe"}
  • ages 定义为 Integer() = {25, 30, 35}
要将第一个序列中的元素与第二个序列中的元素合并,请应用 Join() 函数,如下所示:
names.Join(ages, Function(name) name(0), Function(age) age Mod 10, Function(name, age) $"{name}: {age}")names.Join(ages, Function(name) name(0), Function(age) age Mod 10, Function(name, age) $"{name}: {age}")
输出为 {"John: 25", "Jane: 30", "Joe: 35"}

VB 函数:First

First() 函数返回序列中满足指定条件的第一个元素。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取序列中的第一个偶数,请应用 First() 函数,如下所示:
numbers.First(Function(n) n Mod 2 = 0)numbers.First(Function(n) n Mod 2 = 0)
输出为 2

VB 函数:First Or Default

FirstOrDefault() 函数返回第一个元素,如果没有元素满足条件,则返回默认值。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取序列中的第一个奇数,请应用 FirstOrDefault() 函数,如下所示:
numbers.FirstOrDefault(Function(n) n Mod 2 = 1)numbers.FirstOrDefault(Function(n) n Mod 2 = 1)
输出为 1

VB 函数:Last

Last() 函数返回序列中满足指定条件的最后一个元素。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取序列中的第一个偶数,请应用 last() 函数,如下所示:
numbers.Last(Function(n) n Mod 2 = 0)numbers.Last(Function(n) n Mod 2 = 0)
输出为 4

VB 函数:Last Or Default

LastOrDefault() 函数返回最后一个元素,如果没有元素满足条件,则返回默认值。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取序列中的第一个奇数,请应用 FirstOrDefault() 函数,如下所示:
numbers.LastOrDefault(Function(n) n Mod 2 = 1)numbers.LastOrDefault(Function(n) n Mod 2 = 1)
输出为 5

VB 函数:Skip

Skip() 函数会跳过序列中指定数量的元素。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要跳过序列中的前两个元素,请应用 Skip() 函数,如下所示:
numbers.Skip(2).ToArray()numbers.Skip(2).ToArray()
输出为 {3, 4, 5}

VB 函数:Skip While

SkipWhile() 函数会跳过元素,直到不再满足条件为止。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要跳过小于 3 的数字,请应用 SkipWhile() 函数,如下所示:
numbers.SkipWhile(Function(n) n < 3).ToArray()numbers.SkipWhile(Function(n) n < 3).ToArray()
输出为 {3, 4, 5}

VB 函数:Take

Take() 函数从序列开头返回指定数量的元素。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取序列中的前三个元素,请应用 Take() 函数,如下所示:
numbers.Take(3).ToArray()numbers.Take(3).ToArray()
输出为 {1, 2, 3}

VB 函数:Take While

TakeWhile() 会返回元素,直到不再满足条件为止。
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要获取小于 4 的数字,请应用 TakeWhile() 函数,如下所示:
numbers.TakeWhile(Function(n) n < 4).ToArray()numbers.TakeWhile(Function(n) n < 4).ToArray()
输出为 {1, 2, 3}

VB 函数:Any

如果序列中的任何元素满足指定条件,则 Any() 函数将返回 true
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要确定序列中是否至少有一个数字为偶数,请应用 Any() 函数,如下所示:
numbers.Any(Function(n) n Mod 2 = 0)numbers.Any(Function(n) n Mod 2 = 0)
输出为 true

VB 函数:All

如果序列中的所有元素都满足指定条件,则 All() 将返回 true
假设您将一个名为 numbers 的变量定义为 Integer() = {1, 2, 3, 4, 5}
要确定序列中的所有数字是否都是正数,请应用 All() 函数,如下所示:
numbers.All(Function(n) n > 0)numbers.All(Function(n) n > 0)
输出为 true

VB 函数:Add item to list

列表函数 AddItemToList() 可将新项目添加到现有列表中。
假设您要使用“设置值”规则,使用来自流程集成的数据处理“编辑网格”控件中的记录。要设置的项目为 Processes.ALLDATATYPES.out_genericList
要将项目添加到通用列表,请为其分配以下值:
AddItemToList(Processes.ALLDATATYPES.out_genericList, MainPage.EditGrid.NewItem)AddItemToList(Processes.ALLDATATYPES.out_genericList, MainPage.EditGrid.NewItem)

VB 函数:Delete item from list

列表函数 DeleteItemFromList() 用于从现有列表中删除项目。
假设您要使用“设置值”规则,使用来自流程集成的数据处理“编辑网格”控件中的记录。要设置的项目为 Processes.ALLDATATYPES.out_genericList
要从通用列表中删除项目,请为其分配以下值:
DeleteItemFromList(Processes.ALLDATATYPES.out_genericList, MainPage.EditGrid.RowIndex)DeleteItemFromList(Processes.ALLDATATYPES.out_genericList, MainPage.EditGrid.RowIndex)

VB 函数:Update list item at index

列表函数 UpdateListItemAtIndex() 可更新现有列表中的项目。
假设您要使用“设置值”规则,使用来自流程集成的数据处理“编辑网格”控件中的记录。要设置的项目为 Processes.ALLDATATYPES.out_genericList
要更新通用列表中的项目,请为其分配以下值:
UpdateListItemAtIndex(Processes.ALLDATATYPES.out_genericList, MainPage.EditGrid.RowIndex, MainPage.EditGrid.SelectedItem)UpdateListItemAtIndex(Processes.ALLDATATYPES.out_genericList, MainPage.EditGrid.RowIndex, MainPage.EditGrid.SelectedItem)

此页面是否有帮助?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.