Remove part of a string from a larger one

Hello all

Lets say i have 1 massive string (scrape of entire document), Let’s call it STR1. Within STR1 there is a bunch of text that i have called STR2.

Is there an easy way to remove STR2 contents from the contents of STR1 and output that as STR3?

Kinda like a reverse concatenate?!?!?

EG
STR1: AABBAA
STR2: BB
so STR3 would be AAAA

**Very small example, as my actual strings are hundreds of characters long, so doing a STR1.ToString.Replace(“BB”,“”).Trim would not be feasible.

I have a work around by doing StringSplits but it’s involved and complex…Hoping someone has easier idea.

Thanks

Regex can certainly help you with this

Hi,

You can use Regex.
Go through this link hope it will help.

Thanks!

Indeed regex.replace will do the trick

Hi @MikeBlades,

If your second string variable, STR2 holds consecutive strings, you can remove it by using
STR3=System.Text.RegularExpressions.Regex.Replace(STR1,STR2,"")

or

STR3=STR1.Replace(STR2,"")

If you would like to remove discontinuous pattern, you can use a string array contains each string elements to be removed. Loop it through each elements in the array and use any of the above methods to remove the array elements.

Warm regards,
Nimin