陣列 Array - YenLinWu/RPA_UiPath GitHub Wiki

  • 陣列初始化 Initiate an Array

New String(1){} 可存放2個字串項目的空陣列
New String(2){} 可存放3個字串項目的空陣列
New String(){ "A", "B", "C" } 賦予初始值的字串陣列
New Integer(){ 1, 2, 3, 4 } 賦予初始值的整數陣列

  • 陣列轉列表 Convert Array to List

list_Variable = arr_Variable.ToList

  • 列表轉陣列 Convert List to Array

arr_Variable = list_Variable.ToArray

  • 串連字串陣列的所有項目(且在每個項目之間使用指定的分隔符號) Concatenates all the elements of a string Array
    e.g. {"A","B","C"} 陣列以 "\" 串聯所有的項目後成為 "A\B\C" 字串

str_Variable = String.Join( "\", arr_Variable )

  • 轉換字串型態的整數陣列成為整數型態的整數陣列 Convert string Array to integer Array
    e.g. {"1","2","3"} 陣列轉成 {1,2,3} 陣列

arr_IntArray = Array.ConvertAll( arr_StringArray, Function(x) CInt(x.trim) )

  • 取得整數陣列中的最大值/最小值 Get the maximum/minimum item of an integer Array
    e.g. {1,2,3} 整數陣列中的最大值為 3 及最小值為 1

最大值 int_Max = arr_IntArray.Max
最小值 int_Min = arr_IntArray.Min

  • 取得陣列中的最後一個元素 Get the last item of an Array
    e.g. 從 {"A","B","C"} 陣列中取得最後一個元素 "C"

str_last = arr_Variable( Ubound(arr_Variable) )

  • 陣列反序 Reverse an Array
    e.g. { "A", "B", "C", "D" } 陣列轉成 { "D", "C", "B", "A" } 陣列

arr_Variable = arr_Variable.Reverse().ToArray

  • 移除陣列中的最後一個項目 Remove the last item of Array

arr_Variable = arr_Variable.Take( arr_Variable.Count-1 ).ToArray

  • 移除陣列中的第一個項目 Remove the first item of Array

arr_Variable = arr_Variable.Skip(1).ToArray

  • 移除陣列中的前 k 個項目 Remove the first k items of Array

arr_Variable = arr_Variable.Skip(k).ToArray

  • 刪除陣列中某一個特定的項目 Delete an item from an Array

arr_Variable = arr_Variable.Where( Function(s) s<>"element" ).ToArray
字串陣列 arr_Variable = arr_Variable.Except( New String(){ "element" } ).ToArray
整數陣列 arr_Variable = arr_Variable.Except( New Integer(){ "element" } ).ToArray

  • 刪除陣列中多個特定的項目 Delete items from an Array

arr_Variable = arr_Variable.Where( Function(s) s<>"element 1" And s<>"element 2" ).ToArray
字串陣列 arr_Variable = arr_Variable.Except( New String(){"element 1","element 2"} ).ToArray
整數陣列 arr_Variable = arr_Variable.Except( New Integer(){"element 1","element 2"} ).ToArray

  • 篩選出陣列中符合特定條件的項目 Filter items from an Array with the conditions

e.g. 從字串陣列 arr_Variable 中,篩選出字串開頭不為 "Column" 的項目

arr_Variable = ( From item In arr_Variable Where Not item.StartsWith( "Column" ) Select item ).ToArray