(01-06-2021, 01:40 AM)Kostolany Wrote: (01-06-2021, 01:33 AM)miso Wrote: (01-06-2021, 01:05 AM)Kostolany Wrote: I was doing some research about the substring method when I saw these.
Ive seen them multiple times but never really know how they work.
Would someone mind explaining it to me or maybe telling me how this notation is called so I can do research on myself?
I would greatly appreciate it.
http://prntscr.com/wh4aha
Substring basically takes whats inbetween the 2 ints you've given it on the string you want. For example lets use "Hello World", setting the starting index at 3 & the ending index at 7, the result will be "lo Wo", the result is whatever is inbetween the 2 indexes youve entered
Yes I am aware of that. Im sorry if I wasnt clear enough but my question was about the red underscored passages of the screenshot.
I know this notation:
Code:
Console.WriteLine($"{variable}");
But I have never heard of this one. Furthermore I dont know how this works, what the name of it is or even how to use it.
Code:
Console.WriteLine("{0} random filler string {1}");
Like used in the Screenshot. I hope this clears things up.
In fact your question is not about substring, its about string formatting,
When you pass two or more argument to `Console.Write`, its automatically substitute the second parameter and upper values, inside the first parameter string "{0} random filler string {1}" by replacing the `{n} ` sub string with the n'th parameters passed to `Console.Write`.
for example :
Code:
String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now);
the result string will be the string `Name = {0}, hours = {1:hh}` where the {0} and {1} are replaced with the first parameter `name` and the second parameter `DateTime.now` values
`Name = fragx1011, hours = 21}`
its in fact a global approach used in many language for formatting string
you can google that : The .NET composite formatting