Our code base has a lot of StringBuilder.AppendFormats that have strings that end with newline characters. I've made an extension method called AppendLineFormat and would like to use Resharper's Custom Patterns feature to identify and fix those old calls to use the new extension method (and to suggest this new extension method to others in the future).
StringBuilder sb = new StringBuilder();
int i = 1;
sb.AppendFormat("i is {0}\r\n", i);
into
sb.AppendLineFormat("i is {0}", i);
Is there a way to use regex (with replacement) to identify strings that match? I don't want to turn every AppendFormat into an AppendLineFormat - only the ones with strings that end in \r\n. Here's what I've got so far.
Search Pattern:
$sb$.AppendFormat($newLineString$,$args$)
Replace Pattern:
$sb$.AppendLineFormat($newLineString$,$args$)
Where
"(.*)\\r\\n"
(totally wrong, I know)Unfortunately as for now it's not supported.
There is a bunch of issues, you can vote for them:
As a workaround you can use Visual Studio Find and Replace feature.
Search pattern:
\.AppendFormat\(\"(.+?)(?>\\r\\n\")
Replace pattern:
.AppendLineFormat("$1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With