Strip out certain data from a string

I’m creating a robot which required to change the amount in a system, based on a request which will be received from 3rd party. There are several type of request (as shown below) that will be received

Request type possibilities:
“32 EUR”
“INR 48.2”
“Please change the cash amount to 87 SGD”
“Please change from 28 MYR to 52.7 ROL”

Basically, I want the robot to strip out currency and the amount only to a variable.

Can anyone please help me on this?

1 Like

@Serran_Neru You need a design for this robot. I will give some outline design as follows:

  1. capture all received inputs to change system in a note pad (later you can create a live template to capture them) depends of your system where you receive the data(from 3rd party).
  2. Read note pad line by line into a string.
  3. each line will have numbers for respective currency. please use string manipulations like split, trim, right, left functions and get your desired values from the string.
  4. invoke your local system to post grabbed data.

If you spend some time on this forum search you can find WF for reading a note pad line by line. You also can get string manipulations in this forum…

image
image
above steps will be useful to create a WF to read text file line by line.

happy UiPathing…

1 Like

@Serran_Neru

First Create a list of strings of currencies of different nations let us take ListA

ListA={“EUR”,“INR”,“SGD”,“MYR”,“ROL”}.ToList()

Let’s take stra=“Please change the cash amount to 87 SGD
ListB=stra.Split({" "},stringSplitOptions.RemoveEmptyEntries).ToList.Where(Function(Item) **
** IsNumeric(Item) or ListA.Contains(Item.ToUpper)).To List()

Now Your Required Output Will Be
StrOutput=string.join(" ",ListB)

Regards,
Mahesh

1 Like

@Serran_Neru, Use this in Matches activity, (Not a best solution albeit :wink: )

Input - Your string
Pattern - \b[A-Z]{3}\s(\d+.\d+|\d+)|(\d+.\d+|\d+)\s[A-Z]{3}
Output - Variable with IEnum< Match>

Regards,
Dom :slight_smile:

1 Like

Hi Mahesh,

This is helpful for me. But what does “****” means. The code shows error when i use that.

@Serran_Neru
Can you share the screen shot of the error.

Regards,
Mahesh

@Serran_Neru

I think you copied the ** from the code what i have posted in forum, thats just used for Highlight the code
Now use the below code
ListB=stra.Split({" "},stringSplitOptions.RemoveEmptyEntries).ToList.Where(Function(Item)
IsNumeric(Item) or ListA.Contains(Item.ToUpper)).To List()

Regards,
Mahesh

Mahesh, looks like something was missed here.

It still shows the same. Presenting the screen shot, hope you can help. :frowning:

1 Like

@Serran_Neru

List A and List B are not array of strings , they are List of strings

TO select the List Of strings In Variable type select Browse and type List, In list select for strings List
After creating ListA of type ListA use the below syntax
ListA={“EUR”,“INR”,“SGD”,“MYR”,“ROL”}.ToList

Or Instead try removing .ToList at Last and give .ToArray

Regards,
Mahesh

Perfect that works!

:frowning: not for me, I tried both ToList and ToArray and its the same.

Try ToArray()

Hi @Serran_Neru,

use Matches activity

Pattern
Input - your input string
Pattern - (([A-Z]{3}.)[\d]+(\.[\d]+)?)|([\d]+([\.[\d]+]?)(.[A-Z]{3}))
Output - Variable with IEnum< Match>

use this pattern to get the data.
1.32 EUR
2.INR 48.22
3.87 SGD
4.28 MYR
5.52.7 ROL

from here you can take the value

Regards,
Arivu

1 Like

@Serran_Neru

For me it’s working fine. I have already tested the code.
I think the issue is with double coats,Try once by deleting and adding double coats inside flower bracket

Regards,
Mahesh

@arivu96, Its a Duplicate :wink:

This one fails if we have a string in this format

TOP 82.5 EUR ,

but our regex will extract TOP 82.5 which is a wrong output.
But we can make it a better solution. Just need a slight modification :smile:

Regards,
Dom :slight_smile:

Thanks guys :slight_smile:

@Serran_Neru

Is it worked?

Regards,
Mahesh

Yes Mahesh, I got it and I did it in a better way with lots of suggestion I got

@Serran_Neru

Hmm k. :grinning:

Regards,
Mahesh