一、變數
創建變數有三種方式
- From the Variables panel – Open the Variables panel, select the ‘Create new Variable’ option, and fill in the fields as needed. When you need it, provide its name in the Designer panel or in the desired Properties field.
- From the Designer panel – Drag an activity with a variable field visible (i.e. ‘Assign’) and press Ctrl+K. Name it and then check its properties in the Variables panel.
- From the Properties panel – In the Properties panel of the activity, place the cursor in the field in which the variable is needed (i.e. Output) and press Ctrl+K. Name it and then check its properties in the Variables panel.
好的創建變數:
變數名用駝峰式命名,
設定好變數的作用域,將多個變數不必要地全域化可能會導致效率問題以及混淆的可能性,
二、引數:
引數與變數非常相似——它們動態地存盤資料,它們具有相同的資料型別,并且它們支持相同的方法,不同之處在于它們在作業流之間傳遞資料,并且它們有一個額外的屬性——資料從哪個方向傳遞到哪個方向,方向可以是進,出和進/出,
三、資料型別
- Numeric (category)
Int32 - System.Int32 (signed integers): 10, 299, -100, 0x69
Long - System.Int64 (long integers): 5435435343O, -11332424D
Double - System.Double (allows decimals, 15-16 digits precision): 19.1234567891011
- Boolean
- Date and Time (category)
DateTime:用于存盤特定的時間坐標(mm/dd/yyyy hh:mm:ss),這種變數提供了一系列特定的處理方法(減去天數,計算今天剩下的時間,等等),例如,要獲得當前時間,可以將運算式賦值為DateTime.Now是DateTime型別的變數,
常用的操作方法:
獲取今天日期:DateTime.Today,Datetime.Now.Month
獲取星期:DataTime.DayOfWeek.ToString
字串轉日期型別:DateTime.ParseExact(InputDate, "dd.MM.yyyy", nothing) 將匹配字符中格式為“dd.MM.yy”的日期字串轉為的日期型別,轉后的日期格式為你本地系統設定的格式
TimeSpan:用于存盤關于持續時間的資訊(dd:hh:mm:ss),您可以使用它來度量DateTime型別的兩個變數之間的持續時間,例如,您可以在一個變數(型別為DateTime)中存行程開始時的時間,在另一個變數(型別為DateTime)中存結束時的時間,并將差異存盤在一個型別為TimeSpan的變數中,
myTimeSpan = DateTime1.Subtract(DateTime2)//存盤兩個日期之間的差異 天數 小時數 分鐘數 秒數 myTimeSpan.Days//相差天數
- String
string常用的資料操作方法
concat
連接兩個指定物件的字串表示形式
運算式:String.Concat (VarName1,VarName2)
Contains
檢查指定的子字串是否出現在字串中,回傳真或假
運算式:VarName.Contains("text")
Format
將物件的值轉換為字串(并將其插入到另一個文本中)
運算式:String.Format(“{0} is {1}”, VarName1, VarName2)
IndexOf
回傳字串中某個字符第一次出現的從零開始的索引
Expression: VarName1.IndexOf(“a”)
Join
連接集合中的元素并將它們顯示為字串
Expression: String.Join(“|”, CollVarName1)
Replace
替換字串中子字串的所有匹配項
Expression: VarName.Replace (“original”, “replaced”)
Split
使用指定的分隔符將字串拆分為子字串
Expression: VarName.Split(“|“c)(index)
Substring
使用起始索引和長度從字串中提取子字串
Expression: VarName1.Substring(startIndex, length)
首字母大寫:StrConv(VarName1, VbStrConv.ProperCase);
- Collection集合
這個類別重新統一所有的物件集合,每個物件通過其在集合中的索引進行標識,集合主要用于處理和處理復雜資料,一些最常見的集合是:
1.Array - ArrayOf<T> or System.DataType[]:用于存盤相同資料型別的多個值,大小(物件的數量)在創建時定義,是用于存盤多個物件的固定大小的結構;
2.List - System.Collections.Generic.List<T>: 用于存盤多個相同資料型別的值,就像陣列一樣,與陣列不同,它們的大小是動態的,List允許我們添加、插入和洗掉項,;
Listi定義方式:

List可以存盤大量的元素——名稱、數字、時間坐標和許多其他元素,串列提供了具體的操作方法,如:
添加和洗掉項List.Add()
搜索元素
回圈遍歷專案(并對每個專案執行某些操作)
排序的物件List.Sort List.Reverse反轉
提取項并將其轉換為其他資料型別,
合并兩個List到一個新List:Enumerable.Concat(List1.AsEnumerable,List2.AsEnumerable).ToList
獲取前3個Item:List.GetRange(0,3) 引數1:起始位置;引數2:獲取個數
3.Dictionary - System.Collections.Generic.Dictionary<TKey, TValue>: 用于以(key, value)對的形式存盤物件,其中兩者都可以是單獨的資料型別,
字典(或Dictionary)是(鍵,值)對的集合,其中鍵是唯一的,想想手機中的地址簿,每個名字都有相應的資料(電話號碼、電子郵件),
在實體化變數時,必須選擇鍵和值的資料型別,字典中的資料型別可以是任何受支持的變數(例如,包括字典),
定義:

Dictionary<String, List<String>>
Dictionary<String,Dictionary<String,Double>>
最常與字典相關的操作有:
添加和洗掉(鍵、值)對 VarName.Add(Key, Value) VarName.Remove(Key)
檢索與鍵關聯的值
VarName.Item(Key) 通過鍵回傳字典項
VarName.Count 回傳字典項數
VarName.ContainsKey(Key)檢查具有給定鍵的項是否存在于字典中,并回傳一個布林值結果
VarName.TryGetValue(Key, Value) 檢查字典中是否存在具有給定鍵的項,并回傳一個布林值結果,如果找到則回傳值
為現有鍵重新分配新值 VarName(Key) = 新值
獲取字典中所有Value值到List中,可用于遍歷Value值:VarName.Values
練習:給出一個包含年份和名稱的輸入字典,請計算每個獲勝者的勝利次數,并列印所有獲勝者的名字和相應的勝利次數,
- GenericValue
在開發自動化程序時,會出現您不確定將檢索什么型別的資料的情況,為了找到答案,您需要使用一個足夠廣泛的變數運行一些測驗,該變數可以捕獲任何型別的輸入,這就是我們建議臨時使用GenericValue變數的地方,
使用場景:
將逐列比較同一個Excel檔案的兩個版本,列在資料型別方面是不同的,唯一相關的是哪些條目發生了變化
請記住,GenericValue變數最多是一個臨時解決方案,當資料型別應該是什么變得清晰時,我們強烈建議您將其更改為特定的型別,
四、正則運算式
Matches:搜索輸入字串中的所有匹配項并回傳所有成功匹配項,
IsMatch:指示指定的正則運算式是否在指定的輸入字串中找到匹配項,
Replace:將匹配正則運算式模式的字串替換為指定的替換字串,
舉例:
1.從包含多個地址的字串中檢測所有街道號碼和名稱,
輸出所有匹配項,
address="275 S Wall St., Wilmington, OH, 45177 - Virginia USA, 1223 Pamela St., Leesburg, FL, 34748 - 1022 Lincoln Ave, Duquesne, PA, 15110 - US, 1295 N Opdyke Rd, Auburn Hills, MI, 48326 - 19 Orbit Dr, Enfield, CT, 06082 "
正則運算式 Matachs
\b\d{1,8}(-)?[a-z]?\W[a-z|\W|\.]{1,}\W(road|drive|avenue|boulevard|circle|street|lane|way|rd\.|st\.|dr\.|ave\.|blvd\.|cir\.|ln\.|rd|dr|ave|blvd|cir|ln)

2.輸入字串,判斷:
最小長度:8個字符;以大寫字母開頭;最多20個字符
^([A-Z][\w]{7,20})*$
3.替換指定文本內容
給定字串:"Hello Mr <first_name> <last_name>, we would like to invite you to our opening event next week on <day_of_week>. Please confirm by the end of current week.“
InputData.Replace("<first_name>",FirstName.Trim)
4.從字串中提取電子郵件地址(不使用正則運算式)
給定字串:“Please use the following address to contact me [email protected], it's the company email"
IndexTextToFind = InputData.IndexOf("@")
EmailAddress_Part1 = InputData.Substring(0,IndexTextToFind)
EmailAddress_Part1 = EmailAddress_Part1.Substring(EmailAddress_Part1.LastIndexOf(" "))
EmailAddress_Part2 = InputData.Substring(IndexTextToFind +1)
TemporaryIndex=EmailAddress_Part2.IndexOf(" ")
EmailAddress_Part2=InputData.Substring(IndexTextToFind + 1, TemporaryIndex )
String.Format("The email address is {0}@{1} ", EmailAddress_Part1, EmailAddress_Part2)
使用正則運算式:Uipath有寫好的,可以直接用,下拉選擇Email
((?>[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-\/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)

DataTAble
最大的行數:行數限制為16,777,216,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/808.html
標籤:其他
上一篇:【Uipath】GenericValue型別變數用法。
下一篇:超長待機梅雨季
