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 trial

Android Build an Interactive Story App (Retired) Finishing the User Interface Formatting Strings

Sri Krishna
Sri Krishna
1,348 Points

This video is not clear

Mr. Ben please can u explain this video with some clear idea, because i could not understand this , if u can explain with some examples it will be helpful. thank you ...

Rex Wang
Rex Wang
2,089 Points

String,format is something you might be familiar with if you've programmed in C/C++, Python or Java. The static format method takes a format string which contains special tokens that can be translated and replaced with an appropriate text.

Example:

<!-- language: lang-java -->

String.format("I am %d years old", 24); // I am 24 years old
String.format("Favorite sports team is %s and I like number %d", "foobar", 9); //Favorite sports team is foobar and I like number 9

String.format("Favorite sports team is %2$s and I like number %1$d", 9, "foobar");  //Favorite sports team is foobar and I like number 9
Sri Krishna
Sri Krishna
1,348 Points

Hi Rex, To get a dynamic value we have to use this string format right?? , so is this the same format in all programming languages or it differs??

Thank you ..

I haven't seen a language that doesn't have this idea, but the syntax is a little different for each language. C, C++, and Java have a similar basic syntax in a lot of ways so this looks similar, but on the inside they're all very different languages in the way they handle communicating with the computer. For the most part, a lot of things, once you know one programming language, look similar across them all. They're made that way so that someone learning a new language can pick it up quickly if they've ever used any other language.