'C# file manipulation based on string matching condition

I am using c# to manipulate a text file content based on certain condition. One of them is like this:

if any lines contain

.DoSomething(...) 

I will need to replace those lines with a code block like this:

#if NETSTANDARD2_0
    .DoSomething(...);
#else
    .DoSomethingElse(...);
#endif

What's the best way to do this? Of course, initial thought is to loop through all lines and find those lines and once found, do some kind of inserts. But feel like there must be an easier way? Like regex? What's in the (...) is dynamic, each line will have different content.

Thanks for any tip!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source