KOTLIN has this FEATURE? - String Templates

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the alternative is to convert that into a template and that is something that kotlin prefers and is a very magical feature what's up youtube this is dennis panita for tutorials.eu in this video you are going to learn about string manipulation and string templates in kotlin and if you think that's a cool video have definitely hit that like button the subscribe button and also check out the playlist where you learn a lot more about kotlin so let's get started [Music] so when you hover on the values inside our print statement here you can see that there is a suggestion so it says i should convert the concatenation to a template because what we're doing here is we're concatenating right we're adding strings together but the alternative is to convert that into a template and that is something that kotlin prefers and is a very magical feature because it just adds this with a button click so it's pretty cool so here instead of adding two strings together it's one string so it's just this one statement but then it uses this dollar sign and then the variable name so it just says okay at this position please replace the entry in the string with whatever is inside of first char in string at that point so in this case we will receive the same result we will still get the character h but we don't have to add this plus and the empty space and so forth which can be very tedious when you have a very long statement where you use multiple different variables so this dollar sign here it starts a string template expression so let's look at it with a little more depth so here we can actually make a whole sentence and at the same time get values that we need from any variable so we have this first character is and then first char in string and the length of my where my str my string is and then let's use the length of my str so how do i get the length of my sdr well we saw that with this here okay so myster.length gives me the length of the entire string in this case it's 5 plus another 5 and another empty space so it should be 11 right so how do i get the length now of course i could go ahead and create an extra variable that stores the length so let's call this my length and this would be my sdr dot length that could be a way but there is another way how about we just copy this here and put it in there with the dollar sign and you see that this doesn't seem to work properly because there's this dot so let's just run this real quick and it says the first character h and the length of my cr is hello world.length so that's not exactly what i wanted to achieve so how can i make this work properly well the thing is you can just surround it with curly brackets here so let's surround mystr dot length with curly brackets and then it will treat it as an entire statement so now we're using dollar and then the curly brackets with the statement inside that we want to be used so let's run it again and we will see first character h and the length of my sdr is 11. [Music] you
Info
Channel: tutorialsEU - Android
Views: 43
Rating: undefined out of 5
Keywords: Android tutorial, android tutorial for beginners, android how to, Tutorials, Tutorial, Programming, Course, Learn, Step by step, guide, development, programmer, video course, video tutorial, learn how to, Denis Panjuta, string in kotlin, kotlin, string interpolation, kotlin string, kotlin tutorial, kotlin tutorial for beginners, android studio, java vs kotlin, kotlin vs java, learn kotlin, kotlin android, android kotlin, android, programming, freecodecamp, mouredev, string templates
Id: oKU2HRNQ9co
Channel Id: undefined
Length: 3min 57sec (237 seconds)
Published: Mon Dec 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.