Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper Split String literal

I was not lucky in my 15 minutes googling. Maybe bad luck with good keyword?

Why does the Resharper suggest spliting a string in function parameter?

Example:

From this:

return PartialView("Categorias", lista);

To this:

return PartialView("Cat" + "egorias", lista);

I checked documentation here: link

And it says: Split string literal - Splits string literal into two literals.

I want to discover why is this a good practice, what are the fundamental idealogic behind the scenes that achieved this practice.

I don't want to do it without knowing why...

like image 873
Ismael Avatar asked Nov 29 '12 10:11

Ismael


People also ask

How to break up long string?

Easy, use triple quotes to start and end them. s = """ this is a very long string if I had the energy to type more and more ...""" You can use single quotes too (3 of them of course at start and end) and treat the resulting string s just like any other string.

How to split a string into multiple lines in java?

If you want your string to span multiple lines, you have to concatenate multiple strings: String myString = "This is my string" + " which I want to be " + "on multiple lines."; It gets worse though. If you want your string to actually contain new lines, you need to insert \n after each line.


1 Answers

This is not a good practice. Not everything ReSharper suggests is a good practice - it just so happens that your cursor is in that position, so ReSharper gives you the option to split the string. Try it in any string in any position.
ReSharper has similar position based utilities, for example "convert to verbatim string" or "convert to regular string" - neither of which is "better".

like image 178
Kobi Avatar answered Oct 11 '22 02:10

Kobi