SubString Manipulation

Hi everyone,
I am a newbie to UIPath. I want to get the remaining part of the main string by ignoring the extracted substrings.
For ex - “FILGRASTIM,
Injection 120 micrograms in 0.2 mL single use pre‑filled syringe,
Injection 300 micrograms in 0.5 mL single use pre‑filled syringe,
Nivestim®, Pfizer Australia Pty Ltd” is the main string out of which:
FILGRASTIM is Substring A, Nivestim® is Substring B and Pfizer Australia Pty Ltd is Substring C. I want to store the remaining part of the main string “Injection 120 micrograms in 0.2 mL single use pre‑filled syringe,Injection 300 micrograms in 0.5 mL single use pre‑filled syringe” to Substring D.

Is there any way to do this? Thanks in advance.

Yah sure
That’s possible
If the above input is str_input then
str_output = Split(str_input,”:”)(0).ToString

Cheers @kumarmanjeetcr7

@Palaniyappan the above code gives the whole string as the output. What I want is just remaining part of the main string apart from Substring A,B&C as described above in the question

Based on your input string of:

FILGRASTIM,
Injection 120 micrograms in 0.2 mL single use pre‑filled syringe,
Injection 300 micrograms in 0.5 mL single use pre‑filled syringe,
Nivestim®, Pfizer Australia Pty Ltd

What is your desired output string? Can you please type out exactly how you want the output string to look? I am confused on what you’re trying to do and this would help

Hi @Dave
My output string would be “Injection 120 micrograms in 0.2ml single use pre-filled syringe,
Injection 300 micrograms in 0.5 single use pre-filled syringe”

This substring can be dynamic (might contain 1 or more sentence as the above case has 2 sentences) but the other 3 substrings like FILGRASTIM, Nivestim and Pfizer Australia Pty Ltd are constant.

I hope this gives a bit of idea to you

@kumarmanjeetcr7 If the 3 substrings are constant, I would add them as variables, then use string.replace() method to remove them from the original string to create the final substring.

Assign str0 = "FILGRASTIM,
Injection 120 micrograms in 0.2 mL single use pre‑filled syringe,
Injection 300 micrograms in 0.5 mL single use pre‑filled syringe,
Nivestim®, Pfizer Australia Pty Ltd"
Assign str1 = "FILGRASTIM,"
Assign str2 = "Nivestim®,"
Assign str3 = "Pfizer Australia Pty Ltd"
Assign str4 = str0.Replace(str1,string.empty).Replace(str2,string.empty).Replace(str3,string.empty).Trim()

Now str4 would contain only the characters not found in the substrings you mentioned. It also has the benefit of being quite clear what you’re attempting so it should be easy to review and quickly see what’s happening

Thanks @Dave. I got the idea now… A bit of change in the code is required to make the code dynamic. But thanks for showing the way to approach to this issue :slight_smile:

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