I often find myself writing
var message = "Hello {0}";
and then going back and typing in
var message = string.Format("Hello {0}", world);
It would be nice if as I were typing the string, when I put the ” at the end, resharper figured out there was a parameter in the string and immediately surrounded the string with the string.Format method and put the cursor at the first argument.
Is there a straightforward way to do this? I’m using Resharper 6.1
Just type it in dumber:
Alt+EnterEnter, done1:
Obviously, this also works when the whole thing is much more complex. I know it will strip useless calls to
.ToString(), and I suspect it will automatically lift any format expressions, likeAlt+EnterEnter
1 If you’re unlucky/the surrounding code contains many things that trigger Resharper suggestions(?) you might have to position the cursor over one of the
+operators