String manipulation dynamically

hi

if I have a string β†’ which has some values separated by comma, like below
TK,UI,OP,FG
or
RT,YU,QR,LK
or
PO,TY
or
OP,QR
or
empty

if my sting can be of any of above sample, and I want to replace OP and QR with nothing then how to achieve? output string should only contain non OP QR Values separated by comma

1 Like
Input = TK,UI,OP,FG

Output = If(Input.Contains("OP") OrElse Input.Contains("QR"), Input.Replace("OP,","").Replace("QR,",""),Input)

Hi @S_Nitin

Please use above query in assign activity

Regards

1 Like

@vrdabberu thanks for reply.
will this work if OP and QR at end ,as you are replacing OP, , at last there will not be comma.
also what if string has only single OP?

TK,UI,OP,FG
or
RT,YU,QR,LK
or
PO,TY
or
D3,OP
or
OP,QR
or
OP
or
empty

Hi @S_Nitin

Can you try the below syntax:

Input = "TK,UI,OP,FG".

Output = String.Join(",", Input.Split(","c).Where(Function(s) s <> "OP" AndAlso s <> "QR"))

Regards

1 Like

I will try and will let you know for sure :slight_smile: thanks !

  • Read the Input String: Use the Input Dialog activity or define the string directly in an Assign activity.
  • Split the String: Split the string into an array of substrings based on the comma separator.
  • Filter the Array: Use LINQ or a For Each loop to filter out the unwanted values (β€œOP” and β€œQR”).

@vrdabberu thanks I tested its working :slight_smile:

HI @S_Nitin

You’re welcome bro

Happy Automation !!

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