Does anybody know what class function is for checking if a string has any letter in upper case?

string FirstName_LastName

any function return the idex of char[] that is upper case ? thank you

9 Years
Discussion Span
Last Post by deadrabit

You could examine the string character by character, using the isupper( ) function from library <cctype>. When you find one, return that index.

Or, make use of the string function find_first_of( ) as this sample shows

#include <iostream>
using namespace std;

int main()
    string s = "heLlo, World";
    int spot = -1;

    spot = s.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );

    cout << spot << endl;

    return 0;

The output should be 2, which is the zero based index of the first capital letter.


im pretty sure there is a C library that has all kinds of functions like that.

alternatively you can just look at an ascii key code table and fidle with the numbers.

its pretty simple A + 32 = a, B + 32 = b
ascii was designed that way.

A=65 iirc

just iterate through your cstring (i dunno if offset opperator [] works with string.) checking if anything is between 65 and 91.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.