Dart .parse()
Anonymous contributor
Published Jun 4, 2024
Contribute to Docs
In Dart, the .parse() method is used to convert a string representation of data into a specified data type. It is commonly used to parse strings into numeric values, such as integers or doubles.
Syntax
dataType.parse(string)
The above syntax dataType.parse(string) represents a method call in Dart that converts the string string into the specified data type dataType.
Example
In the following example, the .parse() method is used to convert the string 42 into an int and another string 3.14 into a double:
void main() {String numberAsString = '42';String doubleAsString = '3.14';int number = int.parse(numberAsString);double doubleNumber = double.parse(doubleAsString);print(number);print(doubleNumber);}
The above code will produce the following output:
423.14
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.
Learn Dart on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours