I am reading text from a file into a string builder, I make a quick replacement using .Replace(), then I need to run two regex against the string builder to completely overwrite the string builder. What is the best way to do this?
I used Append to initially load the StringBuilder from the streamreader, then used .Replace() for the simple replacement. Now I need to remove the beginning and end of each line based on two different regex.
You will have to convert the
StringBuilderinto a string (calling itsToString()method) and perform the Regex operations on the string.Also if you are just interested in reading all text from a file, you don’t need to use a stream and a
StringBuilder, instead just useFile.ReadAllText(someFile)which returns a string, orFile.ReadAllLines(someFile)which returns a string array .