Introduction to Dart
Introduction to Dart
String properties and methods
What is the difference between method and property ?
Methods are like operations or actions you can perform on an object. For example, think of a ball. When you kick the ball, that's an action - a
method. You're doing something with the ball.
Properties are like characteristics of an object. For example, the color of the ball or its size. Properties describe the object but don't perform actions on it.
So, methods are actions, and properties are characteristics. In the case of
String, methods, and properties can be used to work with text.
length- Returns the length of the string including space.
First, a variable word is created, and it's assigned the
length property is called on the word
String. This property counts the number of characters (letters) in the
String and returns that value.
The obtained value (the number of characters in the 'Codefinity'
String, which is 10) is passed to the
print() function for output.
As a result, the number 10 is displayed on the screen, indicating the number of characters in the 'Codefinity'
isEmptymethod is used to check if a string is empty, meaning it doesn't contain any characters.
isEmpty method helps to check if a
String is empty, returning
true if the string is empty or
false if the
String contains at least one character. This is useful for determining whether certain actions should be taken based on whether a
String is empty or not.
toLowerCase(): This method converts all characters in a
Stringto lowercase. It allows you to ensure a consistent lowercase representation of characters, which can be useful when comparing two strings regardless of their case or when you want the text to be consistently in lowercase.
toUpperCase(): This method converts all characters in a
Stringto uppercase. It's used to create text where all letters are in uppercase, which can be helpful when you want to display text in a title-like format or make the text more prominent.
toUpperCase() methods allow you to easily manipulate the case of characters in strings, making them valuable in various programming and text processing scenarios.
Everything was clear?