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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,226 questions

56,128 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 187 views
1 answer 158 views
1 answer 234 views
1 answer 187 views
1 answer 186 views
186 views asked Oct 12, 2022 by avibootz
...