{

How to capitalize the first letter of a string in dart?| Flutter By Example


parse String to or from Integer in Dart

In these examples, Learn how to capitalize the first letter of a string or statement in Dart programming with examples.

The string contains a group of words separated by spaces and enclosed in single or double-quotes.

For example, if the string contains ‘hello world’, capitalize of a string is ‘Hello world’.

How to capitalize the first letter of a string in Dart

In this example, Written capitalizeFirstLetter function

  • takes input as String and return String type
  • In the function, Convert the first letter to Uppercase, appended to a substring excluding the first character.
  • This function is called from the main function

Here is an example

void main() {
    print(capitalizeFirstLetter('hello world'));
  
}
String capitalizeFirstLetter(String str) => str[0].toUpperCase() + str.substring(1);

Output:

Hello world

Another way using string append with interpolation syntax

void main() {
  String message = 'hello world';
  print('${message[0].toUpperCase()}${message.substring(1).toLowerCase()}');
}
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.





Related posts

Dart| Flutter How to: Find a Given String is numeric or not

How to iterate loop Enum in Dart | Get Enum with index in Flutter By Example

Dart Enum comparison operator| Enum compareByIndex example| Flutter By Example

Dart tutorial examples/ Flutter By Examples

How to add Methods or Values to Enums in Dart | Flutter By Example

How to convert Double to Integer or Integer to double in Dart| Flutter By Example

How to: Enum to String in Dart | Print Enum name as String in Flutter By Example