Fetching specific value from string

Hi Everyone, I am new to string operations and I need to fetch the string between the second slash ‘/’ and next space in below string. In this case, the string to be fetched is KSHARMA.

Job 243955/X115949A1 /KSHARMA is locking account 41 38142

One of the way of achieving it is doing splitstring with ‘/’ as delimiter and getting text ‘KSHARMA is locking account 41 38142’ from third array element. Then again doing splitstring on this third array element with space ’ ’ as delimiter and getting KSHARMA in first array element.

However this would be long process and I am sure there can be better way of achieving this, probably in one shot. Any help on it would be greatly appreciated. Thanks!

Hi @Kapil,

You can use Regex with this one.

  1. Use Matches activity
    1.1 The input should be the string.
    1.2 Pattern should be “(?<=/)(.*?)(?=\ )”
    1.3 Result is of type string. (let’s say arrMatches as variable name)
  2. It matches two strings. So you will use arrMatches(1).ToString to get KSHARMA

Check this sample workflow:BlankProcess52.zip (11.9 KB)

1 Like

I am getting below error while launching code probably due to lower version of uipath. Can you please let me know the exact regex expression you are using.

Could not find member ‘IsBuilderTabModified’ in type ‘http://schemas.uipath.com/workflow/activities:Matches’. Row: 67, Column: 130

Buddy @Kapil
Here you can go for split method itself with a single shot buddy
in_text = “Job 243955/X115949A1 /KSHARMA is locking account 41 38142”
then
out_text = split(split(in_text,“/”)(2).ToString," ")(0).ToString
this would give you the KSHARMA value in a single step buddy

or
try this buddy with regexp
“(?<= \/)(.*?)(?=\ )”
in matches regularexp and pass the string you want buddy, get the output with variable out_text
and get them directly like this buddy out_text.tostring buddy @Kapil in one shot as you expect buddy


Cheers

Please install System.Text.RegularExpressions package

1 Like

Hi @Kapil,

Please try below code:

NewString.Substring(NewString.LastIndexOf(“/”)+1).Split({" "}, StringSplitOptions.None)(0)

Regards,
Sasikumar K

Did that work buddy …
were you able to get that string @Kapil

I did lookup for this package in uipath forum and as per them, we cant install this package but can add it to imports. I did same however faced same error.

However I got solution to my problem using Split option. Thanks for your help!

1 Like

@Sasi.lalo, it would help me in testing if you let me know the complete expression which I can use in assign activity.

Hi @Kapil,

This will return a string value. So you need to create a string variable and assign this expression to that variable.

Regards,
Sasikumar K

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