Dart StringDart String is a sequence of the character or UTF-16 code units. It is used to store the text value. The string can be created using single quotes or double-quotes. The multiline string can be created using the triple-quotes. Strings are immutable; it means you cannot modify it after creation. In Dart, The String keyword can be used to declare the string. The syntax of the string declaration is given below. Syntax:Printing StringThe print() function is used to print the string on the screen. The string can be formatted message, any expression, and any other object. Dart provides ${expression}, which is used to put the value inside a string. Let' have at look at the following example. Example - Output: this is an example of a single-line string this is an example of a double-quotes multiline line string this is a multiline line string using the triple-quotes The sum is = 30 String ConcatenationThe + or += operator is used to merge the two string. The example is given below. Output: Welcome To JavaTpoint String InterpolationThe string interpolation is a technique to manipulate the string and create the new string by adding another value. It can be used to evaluate the string including placeholders, variables, and interpolated expression. The ${expression} is used for string interpolation. The expressions are replaced with their corresponding values. Let's understand by the following example. Output: Hello World! The result is = 6 My name is Peter, my roll number is 101 Explanation - In the above code, we have declared two strings variable, created a new string after concatenation, and printed the result. We have created two variables that hold integer value then performed the mod operation and we printed the result using the string interpolation. We can use the string interpolation as a placeholder, as we have shown in the above example. String PropertiesThe Dart provides the following string properties.
String MethodsThe Dart provides an extensive range of methods. The list of a few essential methods is given below.
Next TopicDart Lists |