Strings
Anonymous contributor
Published Jun 1, 2024
Contribute to Docs
A String
is a sequence of characters (such as letters, numbers, and symbols) that is used to represent text. It is a data type designed specifically for handling and manipulating textual data. Single-line strings are enclosed in single (‘) or double (“) quotes, whereas triple quotes (‘’’) are used to represent multi-line strings.
Syntax
Here is the syntax for single, double, and triple quoted strings in Dart:
String singleQuoteString = 'This is a Dart string with a single quote.';String doubleQuoteString = "This is a Dart string with double quotes.";String multiLineString = '''This is a multi-linestring in Dart using a single quote.It allows to writetext across multiple lines.''';
Example
The following example determines and prints a message based on the value of the String
variable name
and the int
variable age
:
void main() {String name = "Alice";int age = 30;String interpolatedString = "Hello, my name is $name and I am $age years old.";print(interpolatedString);}
The above code gives the following output:
Hello, my name is Alice and I am 30 years old.
Strings
- .length
- Returns the number of characters within a given string.
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.