If string contains a word from an array and remove that word


I have an array with strings, like {“Lda”, “S.A.”, “S. A.”} called array_company, and I want to remove that terms, probably with a TrimEnd() if a string called str_nameCompany ends with one of that expressions… How can I do it?

–use a for each loop and pass the above array as input and change the type argument as string
–inside the loop use a if condition like this
if true it will go to THEN part where we can use a assign activity like this
str_output = str_nameCompany.ToString.Replace(item,"")

hope this would help you

with respect to @AndyD suggestions
condition be like
remaining same @Aqua1986


1 Like

Thats what I was thinking but the problem occurs if you have a company called SERIALdark or something similar as the Lda will be replaced to produce SERIArk

1 Like

If you don’t have too many strings (less than a million would probably be fine) then I’d just do it within a for each loop.

For each str within array_company (TypeArgument = String)
If activity: StringToCheck.Endswith(str) // note if you want it case insensitive then change it to .EndsWith(str,StringComparison.CurrentCultureIgnoreCase)
Then (true side) Assign checkStr = Regex.Replace(checkStr,str + "$",string.Empty)
Else (false side) - leave this side empty

1 Like

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