Extracting string using split

hi everyone,

I’m new to uipath and I have a question

I need to extract "After the US dollar index rose sharply last night, the Asian currency generally weakened today, and the Taiwan dollar also opened lower. ”
from the string below, using split function

“TWD: 31.000~31.150

After the US dollar index rose sharply last night, the Asian currency generally weakened today, and the Taiwan dollar also opened lower.

ZAR: 14.0000~14.1500

The South African rand rose against the dollar on Thursday, hitting a three-month high and rising with other emerging market currencies as the dollar was weighed down by US interest rate cuts. "

However, the part I would like to extract is dynamic, meaning that it changes everyday

Does anyone know how can I do it?

Example1.xaml (4.8 KB)

Here, maybe this will help

Hi @bhe98,
You can split the string by new line and take second value.
StrVarName.Split(Environment.NewLine.ToCharArray)(1)
Cheers.
Vashisht.

Thanks guys

But what if I just want to extract the rate i.e. “31.000~31.150”, which isn’t a new line.

How can I do it ?

@bhe98, u can use regular expression by using isMatch activity for the number

Hi @bhe98,
After splitting with new line you can again split it by :

Hi @bhe98,

I’ll suggest you to use Matches activity and give input as your string variable,

  1. Set pattern as —> "(?<=TWD: ).+?(\n)" for getting text after TWD:

OR

Set pattern as —> "(?<=\n).+?(\n)" for getting desire text as you mentioned in your topic.

  1. In messageBox —> Text(0) , where Text is output variable of Matches activity,
    :slight_smile:
1 Like

Nice! I was struggling a bit with that Regex. Nice work!
if you could tell me, what is the difference between “(?<=TWD: ).+?(\n)” and “(?<=TWD: ).*” I used the second one

@srdjan.suc

See, both will work here.
In (?<=TWD: ).+?(\n) —> +? use to get text between, so, it’ll search for TWD: and get text upto newline (\n). So, basically it is useful when you want to extract text between two words.
Nothing else. :slight_smile:

1 Like

thank you so much. it works :slight_smile:

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