Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Like this:
var x = @"first line
second line
third line
last line";
That @ is the key here, no need for \n (new line char for strings) -
Navigatr9286y@gitpush Yeah, no, sorry I should've clarified a bit better. What bothers me is that it makes the code harder to read, and it's more difficult to see what the result is going to be. :/ I was mostly wondering just for the sake of convenience, but if there's no way around it I'll just deal with it.
Oh, and I think maybe a better way to write the Python example might've been:
variable_name = \
"""First line.
Second line.""" -
@Navigatr but its exactly like the python example except that \ is replaced with @ and the first line must always be after @ symbol
I'm not sure how not readable it is :\ -
@Navigatr Not sure why that second/third line not aligned under the first line, it usually should unless you configured your IDE to not do so
-
Put stuff like this into a resource entry? :D I know its not a direct answer to your problem but how you can prevent it.
-
Navigatr9286y@hypervtechnics I'll have to see if there's enough variables for that to feel necessary, but how would I go about that? :o
-
Navigatr9286y@jschmold @electrineer I hadn't really thought much about that tbh. I'll keep both of those things in mind, thanks. :)
-
mt3o19136yFor long strings it's really better to keep them in separate resource files. Not to mention its way easier to make localized version of the app having strings in separate place.
-
Brolls31156yHonestly, I’d go down the resource file route.
It’ll make it way neater, and you get the benefit of possible localisation. -
Navigatr9286y@Brolls Yeah, but this is literally just a class assignment, nothing big by any means. Still, I've been considering it, problem being that I don't know exactly how it works. Would the strings just be stored in a regular .txt file? I'm confused and can't seem to find anything that explains it well when I search around.
-
Brolls31156y@Navigatr in .NET projects you have a built in resource system.
You want this:
https://docs.microsoft.com/en-us/... -
Navigatr9286y@Brolls I won't be able to look at it tonight, but I'll try and read through it this weekend, thank you. :)
-
Brolls31156y
Related Rants
So, in C#, are there any tips or guidelines as to how to write "clean" multiline strings? I mean, imo it doesn't look as neat when the code looks like:
static string kindOfLongVariableName = @"First line of string.
Second line of string...";
With the first line sort of hovering on the side. What I'm used to is with Python where you can just:
variable_name = """'\
First line.
Second line.
"""
And use the '\' to escape the newline, but that obviously doesn't work in C#. Can anyone point me in a direction to start looking? The docs are a bit confusing and not very beginner friendly. :/
question
c#
school related
string literals