Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialrichardking4
2,997 PointsWhat's a format string?
At 7:27, Jeremy says:
"And we'll use a format string, so we'll type a $."
I don't recall this concept having been covered previously — what exactly is a format string?
1 Answer
Steven Parker
231,269 PointsYou gave a time reference but didn't provide a link to the video page. But the basic idea is that interpolation will be performed on a string prefixed with a "$" symbol. This means that it will be scanned for embedded tokens made from variable names or expressions surrounded with braces, and the tokens will be replaced by string representations of the expression's value. For example:
var name = "Mike the frog";
var food = "flies";
Console.Write($"My name is {name} and I like to eat {food}.");
For more details, see this MSDN page on String interpolation in C#.
richardking4
2,997 Pointsrichardking4
2,997 PointsYeah I had assumed these forum posts automatically link to the corresponding video, seeing as each video lists forum posts related to it.
Thanks for clarifying the details! I'll check out that documentation.
richardking4
2,997 Pointsrichardking4
2,997 PointsOh, and here's an even better link that has an interactive exercise specifically designed for people who haven't performed string interpolation before:
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/exploration/interpolated-strings
Steven Parker
231,269 PointsSteven Parker
231,269 PointsForum posts should get a link automatically if you start them using the "Get Help" button on the course page.