Can any one help me like how can I select only numeric from a string and sort in assending order

For example the string is like “$578Uipath123” I have to sort this string and the output should be Like 123578

Hi,

Can you try the following expression?

String.Join("",System.Text.RegularExpressions.Regex.Matches(yourString,"\d").Cast(Of System.Text.RegularExpressions.Match).OrderBy(Function(m) m.Value))

Or if you mean order it as 123 and 578, the following will work.

String.Join("",System.Text.RegularExpressions.Regex.Matches(yourString,"\d+").Cast(Of System.Text.RegularExpressions.Match).OrderBy(Function(m) Double.Parse(m.Value)))

Regards,

Thanks for your quick response, the above code is working fine if the string is “$578Uipath123” but I am failing if the string is like this “$548Uipath301” so I am trying for the Output as follows “013458”

Thanks
Sreenivasa

Hi,

If your expected result is 310548, the second expression in the above post will work.

String.Join("",System.Text.RegularExpressions.Regex.Matches(yourString,"\d+").Cast(Of System.Text.RegularExpressions.Match).OrderBy(Function(m) Double.Parse(m.Value)))

Can you try this?

Regards,

Yes if my Expect is “301548” the condition is working fine But my requirement is “013458”.

Could you help me for this Request

Thanks

Hi,

the first expression will return “013458” as the following.

Can you try this?

String.Join("",System.Text.RegularExpressions.Regex.Matches(yourString,"\d").Cast(Of System.Text.RegularExpressions.Match).OrderBy(Function(m) m.Value))

Regards,

Hello @srinusoft37,

Is going to be always the same way? or can it change?

I mean, in the first example you wanted to get 123578, but in the second one you want to get 013458. It is not the same rule. Do you know when you need to use one rule or another one? As you don’t know it is complicate to automate.

Regards :slight_smile:

Thanks @Yoichi This is working.

Thank you

1 Like

This is varies @Angel_Llull

Thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.