How to find maximum in 2 enumerable values?

Hi,

I had extracted two values using regex form in that I have to find maximum value…Can you please help me on that??

Thank you

Hi @sreemathi.a

Welcome to UiPath Forum!

May I ask, are you looking for the maximum value between the two List (Enumerables) of values ?

yes…

Hi @sreemathi.a

ok, you could try

Math.Max(System.Linq.Enumerable.Max(List1),System.Linq.Enumerable.Max(List2))

where List1 and List2 are initialize and contains Integers

Hi @GreenTea

sorry I do know how to change enumerable value to integer…

Hello

Welcome to the UiPath community forums! :tada:

First you you will need to convert the results to an integer.

Second you will then need to use an IF statement to compare the results. They must be an integer value to do this.

(Away from PC otherwise I would help more)

Hi @sreemathi.a

As @Steven_McKeering correctly indicates you need to identify the result of your regex

Please check the dataType of your enumerable.

  • is it IEnumerable(Of Match) where your dataType is output of your Matches activity
  • or your dataType is List(Of String)
  • or others

Hi @GreenTea @Steven_McKeering

yes my output value is IEnumerable(of Match) datatype and I want convert into integer.

Hi @sreemathi.a

Steps to convert results (dataType: Match) to Integer

  1. For Each
  • TypeArgument is System.Text.RegularExpressions.Match
  • Values is List1
    1.1 Inside For Each, Assign to: your integer variable
    1.2 Assign value: CInt(item.Groups(1).Value)

My assumption is that Regex have correctly capture the groups.

1.3. Inside For Each, Add to collection

  • collection is your List1(Of Int32)
  • item is your integer variable

Remember to initialize your List(Of Int32) first before add to collection

  • variables panel under default: New List1(Of Int32)

Repeat for List2.

Hi @GreenTea

When I used assign: CInt(item.Groups(1).Value) I’m getting complier error as option strict on disallows late binding…

@sreemathi.a - Could you please show your sample text and regex pattern??

In the meanwhile, please take a look at the sample…I have 3 values 1, 21, 2 and you see the max value 21 which is printed correctly…

This is my text and the pattern…

Hope this helps…

@prasath17

My Sample Text is “300 Copay Value…”

Regex form is “\d{1,}”

Can you please share your xaml file??

@sreemathi.a - please try to create a workflow from the screenshot shared and if you face errors let us know. If you ignore string.join you just need only 2 activities.

@prasath17 ok please tell me what you assign in StrOutputN

@sreemathi.a - please ignore those…that was used to show the output of Matches activity…

image

StrOutputN =  String.join(" ",IenRegex)

Write Line

IEnRegex.Max(function(x) (x.ToString))

Hi @sreemathi.a

Check the integer variable type. Should be Int32 not GenericValue