Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to check if the first character of a string is uppercase in Dart

2 Answers

0 votes
void main() {
    var str = "Dart";

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




/*
run:

The first character is uppercase

*/

 



answered Nov 4, 2022 by avibootz
0 votes
bool isFirstCharacterUpperCase(String str) {
    if (str == null || str.isEmpty || str.trimLeft().isEmpty) {
        return false;
    }

    String firstChar = str.trimLeft().substring(0, 1);
    if (double.tryParse(firstChar) != null) {
        return false;
    }
    
    return firstChar.toUpperCase() == str.substring(0, 1);      
}

void main() {
    var str = "Dart";

    if (isFirstCharacterUpperCase(str)) {
        print("The first character is uppercase");
    } else {
        print("The first character is not uppercase");
    }
}





/*
run:

The first character is uppercase

*/

 



answered Nov 4, 2022 by avibootz

Related questions

1 answer 114 views
1 answer 106 views
1 answer 153 views
1 answer 115 views
1 answer 121 views
121 views asked Oct 12, 2022 by avibootz
...