Core Methods of String Objects
This lesson gets you acquainted with some of the most common built-in functions of strings.
We'll cover the following
Some of the core methods are discussed in this lesson. You can find a list of all the String methods in Rust documentation of Strings.
Capacity in Bytes
The capacity
gives the number of bytes allocated to the String, unlike len
which gives the number of bytes taken by the String object.
To get the capacity of a variable in bytes, use the built-in function capacity()
.
Syntax
The general syntax is:
str.capacity()
Here str
is the string whose capacity is to be found.
Note: The length of String will always be less than or equal to the capacity.
Create a free account to access the full course.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy