Dart program to check if a character is uppercase

Dart check if a character is uppercase :

In this dart tutorial, we will learn how to check if the first character of a string is in uppercase or not. You can use the same approach to find out if any character is uppercase or lowercase. This is one common problem and you need to use a third-party library, dart doesn’t have any inbuilt methods.

Dart program :

import 'dart:io';

main() {
  print("Enter a string : ");
  var str = stdin.readLineSync();

  if (str[0].toUpperCase() == str[0]) {
    print("The first character is uppercase");
  } else {
    print("The first character is not uppercase");

Explanation :

In this example, we are using toUpperCase to convert the first character to upper case and comparing it with its actual value. If both are the same, it prints that the first character is uppercase, else it prints as not.

Similarly, you can also use toLowerCase to check it.

Sample outputs :

hello world
The first character is not uppercase

Hello world
The first character is uppercase

Dart check character uppercase

Where is the color and why codevscolor ?

Long story short, I love paintings and I paint on weekends. We(me and my wife) have one Youtube channel. Don't forget to subscribe ❤️❤️🤩