Replacing non-numeric characters

Hi All,

I am obtaining a number from a cell but sometimes other characters are added as per below:
image

How would I check each character to confirm it is non-numeric and remove?
OR
How would I check the first character of the string to confirm its non-numeric and remove?

@chend
Just to confirm are you trying to remove β€œ-” this in String. In that case you can use replace activity to replace it to null.

Or you can convert that complete string to double " Convert.ToDouble(yourstring)", so that it will still show as a numeric value.
To check whether string is numeric or not β€œMicrosoft.VisualBasic.Information.IsNumeric(yourstring.ToString)”

Hi Hemanth,

I want to keep the β€œ-” as it is a negative amount.
As the string contains β€œ=”, I am unable to convert to double as it does not recognise as a number format.
I am trying to remove the β€œ=” but the person filling the cell could place any non-numeric characters.

@chend
Use Replace Activity and use below Regex Pattern.
As you said β€œI am trying to remove the β€œ=” but the person filling the cell could place any non-numeric characters.”. So you have to remove all non numeric characters.

Regex Pattern : [a-z\s_:;'/="]+

If you don’t want to remove alphabets, then use like below
Regex Pattern : [\s_:;'/="]+

Input- String Variable
Regex Option : (IgnoreCase, Compiled)

Regards,
Mahesh

Hi Mahesh,

This is great.

So if I assign Cell = ?-123D123
NewCell = System.Text.RegularExpressions.Regex.Replace(Cell,β€œ\D”,β€œβ€)
This provides the outocme NewCell = 123123

Is it possible to keep the β€œ-”
So it will result NewCell = -123123

@chend

Then use below pattern
[^\d-.]

Regards,
Mahesh

1 Like

Hi Mahesh1,

UIpath did not accept this expression as it provides a compiling error.

Regards,
Darren

You to to give pattern within double coats
β€œ[^\d-.]”

Regards,
Mahesh

1 Like

@chend

use this in assign statement

Numbers = Regex.Match(yourInputString,β€œ\d+”).Value

Thank you. This is my first time using the replace activity.
I am unsure what I have done wrong as it still showing the original value.

Kind regards,

Darren

@chend
you have not assigned any value to the result field. Please once assign the value and let me know whether it is working or not.

Regards,
Mahesh

1 Like

Hi Mahesh1,

Thank you. It worked perfectly.
I accidentally assigned it outside the activity not knowing it required an output assigned within the replace activity.

Regards,
Darren

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