dart
Dart program to capitalize the first letter of a string
In a Dart program, String can be converted to uppercase or lowercase using inbuilt functions toUpperCase() and toLowerCase(). If you want to capitalize the first letter of the Dart String then you can use the below code.
void main() async {
String myStr = "devsheet";
String result = "${myStr[0].toUpperCase()}${myStr.substring(1).toLowerCase()}";
print(result);
}
void main() async {
String result = capitalize("devsheet");
print(result);
}
String capitalize(String str) => str[0].toUpperCase() + str.substring(1);
Here, we have created a capitalize function that will return the String with the first letter in uppercase format and the rest of the letters in lowercase.
Was this helpful?
Similar Posts
- Dart Program to convert a number to string
- Convert string to integer Dart Program
- Dart Program to generate unique id using uuid package
- Dart Program to add Single or Multiple Items to a List
- Dart Program to update or replace List items or values
- Dart program for condition based item removal from a list
- Dart Program to remove the last element from a List