array={“Bhautik”,“99”,“21”,“ajay”,“89”,“10”,“shalu”,“47”,“71”,“69”,“3”,“Rohit”,“19”}
find max and min number.
please solution
array={“Bhautik”,“99”,“21”,“ajay”,“89”,“10”,“shalu”,“47”,“71”,“69”,“3”,“Rohit”,“19”}
find max and min number.
please solution
Try this-
Create a Sequence in UiPath.
Assign your array to a variable. Let’s call it “inputArray.”
Initialize two variables to keep track of the maximum and minimum numbers:
Use a For Each activity to iterate through the elements in the inputArray. Set the TypeArgument to String since the array contains both numbers and names.
Inside the For Each loop, add an If activity to check if the current element is a number.
Use an IsNumeric function to check if the current element is a number. You can do this by using the following condition:
IsNumeric(item.ToString.Trim)
If the condition is True, convert the current element to an integer and compare it with MaxNumber and MinNumber to update these variables if needed.
Convert.ToInt32(item) > MaxNumber
, then set MaxNumber = Convert.ToInt32(item)
Convert.ToInt32(item) < MinNumber
, then set MinNumber = Convert.ToInt32(item)
After the For Each loop, you will have the maximum number in the MaxNumber variable and the minimum number in the MinNumber variable.
You can then use Log Message activities or any other desired actions to display or use these values as needed.
Thanks!
arrValuesVar.Where(Function (x) x.IsNumeric).Select(Function (x) CInt(x)).Min()
arrValuesVar.Where(Function (x) x.IsNumeric).Select(Function (x) CInt(x)).Max()
please share the Xaml
was done within the immediate panel, there is no XAML
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum
You can apply it directly:
Assign Activity
myMin | int32 =
YourArrayVar.Where(Function (x) x.IsNumeric).Select(Function (x) CInt(x)).Min()
Thanks for Solution.
So, the topic can be closed?
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum
=> Create a two variables in int datatype.
=> Assign → inputArray = {“Bhautik”, “99”, “21”, “ajay”, “89”, “10”, “shalu”, “47”, “71”, “69”, “3”, “Rohit”, “19”}
=> Use for each activity to iterate the values in the array
=> Inside For each Insert the If condition as below
If System.Text.RegularExpressions.Regex.IsMatch(item.ToString, "^\d+$") Then
Assign activity: currentNumber = Convert.ToInt32(item)
Else If currentNumber > maxValue Then
Assign activity: maxValue = currentNumber
End If
Else If MinValue = 0 Then
Assign activity: MinValue = CurrentItem
Else If currentNumber < minValue Then
Assign activity: minValue = currentNumber
End ElseIf
End If
End For Each
=> Log Message activity: "Maximum Value: " + maxValue.ToString
=> Log Message activity: "Minimum Value: " + minValue.ToString
Check the below workflow for better understanding.
Hope it helps!!
Hi,
Please refer below workflow
Main.xaml (5.6 KB)