Buda Gavril Buda Gavril - 3 days ago 5
C# Question

resharper: unwrap long string declaration

Can resharper convert this:

var str = "gjkldfhgiodfh hg jkfgh jkhjhklfhfhkl jkghj´kl fjgfhjklgfh fkhgfkl";


Into this:

var str = @"gjkldfhgiodfh
hg jkfgh jkhjhkl
fhfhkl jkghj´kl fjgfhjklgfh fkhgfkl";


I have looked over options in
Code Editing -> C# -> Formatting style -> Line Breaks and Wrapping
at Wrap Long Lines (it's unchecked) and Keep Existing Line Breaks (it's unchecked) but these settings won't help me in this situation.

I have the Ultimate version (2016.2.2).

Thank you.

Answer

No, it can't.

And that's mainly because what you suggest is not simply some nice formatting, but a complete change of content.

When adding a '@' before a string, everything that follows, including newlines, tabs and spaces, will be the content of that string. If you use that string, all content, including the newlines, tabs and spaces will be used as well.

Just try it with a Console.WriteLine:

using System;

public class Program
{
    public static void Main()
    {
        var str = @"gjkldfhgiodfh 
                    hg jkfgh jkhjhkl
                    fhfhkl jkghj´kl fjgfhjklgfh fkhgfkl";

        Console.WriteLine(str);
    }
}

The output will be:

> gjkldfhgiodfh 
>                     hg jkfgh jkhjhkl
>                     fhfhkl jkghj´kl fjgfhjklgfh fkhgfkl

And that's most probably not what you want.

Comments