Struggling with variable trimming

Hello,

I am a RPA beginner and I would like to kindly ask you for help.

My goal is to read and extract information from a web site as a string value, trim it to gain a single number, then declare it as an integer variable.
The string value provided by the selector is like this: “1of7Records:66T” or “Records:2T”

I am using .remove and .replace options to trim the string, but all I get is “1of7Records:66” or “66T” what leads to string to integer conversion failure.

Could somebody advise me how to compose the .remove/replace or regex to get a simple number value?

Thanks in advance

Peter

Hi @Pmm

Input = "1of7Records:66T"

Output = System.Text.RegularExpressions.Regex.Match(Input,"(?<=\:)\d+").Value.Trim()

Let me know if you have any queries

Hope it helps!!

@Pmm
image

System.Text.RegularExpressions.Regex.Replace("1of7Records:66T","\d+\s*of\d+\s*Records:","")

Hello @Parvathy ,

thanks for reply, I am trying to fit your expression to my workflow, but looks like I am doing something wrong:

Extracted_string - declared string variable with the string extracted from the web site.
StringVariable - declared int32 variable to be filled with the trimmed number.

Assign activity:
StringVariable = System.Text.RegularExpressions.Regex.Match(Extracted_string,“(?<=:)\d+”).Value.Trim()

is giving me compiler error the strict on option does not allow conversion string to double :frowning:

What I am doing wrong please?

P.

Hi @Pmm

Try this:
StringVariable = CInt(System.Text.RegularExpressions.Regex.Match(Input,"(?<=\:)\d+").Value.Trim().ToString)

Regards

@Pmm,

Here is more beginner friendly approach.

  1. Let’s just take out the useful string from the whole input string using Split with : as separator.

  2. Then take out the desired number using RegEx.

image

Output:
image

Thanks,
Ashok :slight_smile:

Thanks for the proposed solutions. I will test it and will let you know.

P.

1 Like

Thanks for the patience with me, unfortunately I getting “Directive option strict on” does not allows this error. :frowning:

Hello @ashokkarale ,

Could you be so kind and show me the value of the strUsefulPart please?

Thank you.

@Pmm,

It’s strInput.Split(":")(1).Trim()

Thanks,
Ashok :slightly_smiling_face:

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