Welcome this lecture.
You're going to learn how to get the length of a string.
Let's start.
Now, let's take a look at this example, let's just declare a string variable with an initial value
of call down less time Prenzler.
And here, let's find out the length of the value inside the names variable by typing Lannes name is
just Cipha.
Lan is a built in function so you don't have to import a package to use it.
OK, now let's run this program.
As you can see, it brings four so you can use the land function to find out how many characters in
a string value.
However, this is only true for a string value, which only contains English characters.
Actually, the land function finds out how many bytes string value it actually doesn't find.
How many characters in a string?
Let's change the name variables value to my name, which contains non English letters as well.
I'll return back to this topic afterwards.
But as a teaser, let me tell you that strangelet clothes are made up of Unicode code points.
Call to rooms and rooms are made up of bytes so each character can be one byte or up to four bytes.
I'm going to talk about that later, OK?
Let's return to my name now.
As you can see, there are five letters in my name.
The first letter is E, which is two bites and the next three letters since they are English letters.
Each letter is one bite and the last letter chair is two bites, just like the first non English letter.
So non English characters need more bites, right?
Not these last, but other non English characters can take up to four bites.
Each can guess how many bites there are in my name.
The we do now think about it.
OK, I'm running it now.
As you can see, my name takes seven bites in total, so it's clear that the lamb function just returns,
the bites doesn't return the actual number of characters.
So you cannot trust it for calculating the length of a string value.
Right.
I feel that now you're thinking.
So how can I find out how many characters in a shrink?
Let me show you.
OK, this is the same program I'm going to import a new package called UTF eight.
This package helps you to work with UTF eight encoded string values, and this import statement is a
multiple import statement to save space.
I typed it in one line by using a semicolon between the package names.
There is one more thing here.
The UTF eight package leaves inside the Unicode Packages directory, but UTF eight isn't a package of
the Unicode package.
There is no such packaging.
Engo UTF package is just under the Unicode folder.
This is only for the package organization purposes.
So the real name of the package is only UTF eight.
OK, now I'm going to use a function from the UTF eight package room count in string function takes
on UTF eight encoded string value and returns an integer value it returns.
How many actual characters inside the past think value?
Put simply, a room can represent almost any letters, including English and non English letters.
I'll talk about the rules in detail later.
As you just saw, the land function only counts bytes.
However, this function counts the actual characters inside a string.
So when I say character, I actually mean code points or simple rules.
OK, let's run it now.
As you can see, my name contains five characters, and the room count in string function correctly
returns it.
So when you work with non English characters and first string value is UTF eight encoded, you should
always use this function.
As I said before, all in literal single are UTF eight encoded, but string values are not.
There is a difference.
You'll learn more about this afterwards.
All right, congrats.
Now you learned how to properly find the length of a shrink.
All right.
See you in the next lecture.