Article View: borland.public.cppbuilder.nativeapi
Article #15301Re: Determining the case of a string
From: Dennis Jones
Date: Wed, 09 Jul 2003 05:38
Date: Wed, 09 Jul 2003 05:38
46 lines
2464 bytes
2464 bytes
"Josh Kirkpatrick" <jkirkpat@softhome.net> wrote in message
news:3f0b983a@newsgroups.borland.com...
> Hello, again. My latest question should be very simple to answer.
>
> I need to programatically determine whether a string ("A", "b",etc.) is
> uppercase or lowercase. What's the simplest course of action?
>
> TIA,
> ~Josh
When you say "string", I assume you mean "character", because to ask if a
string is upper/lower case is ambiguous, unless you are talking about
wanting to know if ALL characters in a string are upper/lower case.
Anyway, you can use isupper() and islower() to determine if an individual
character is upper/lower case. If you want to know if an entire string is
upper/lower case, you will have to write your own functions, something like
this:
bool isStrUpper( const char *str )
{
for ( int i=0; i<strlen(str); i++ )
{
// if ( !isalpha( str[i] ) ) return false; // un-comment this line if
you don't want to ignore non-alphabetic characters
if ( islower( str[i] ) ) return false;
}
return true;
}
bool isStrLower( const char *str )
{
for ( int i=0; i<strlen(str); i++ )
{
// if ( !isalpha( str[i] ) ) return false; // un-comment this line if
you don't want to ignore non-alphabetic characters
if ( isupper( str[i] ) ) return false;
}
return true;
}
The implementation of these functions is not particularly efficient, but
they should get you started.
- Dennis
Technical Details
Message-ID:
<3f0baa44$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f0b983a@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,b6b597469f9a3144 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-08 22:40:05 PST From: "Dennis Jones" <djones@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f0b983a@newsgroups.borland.com> Subject: Re: Determining the case of a string Date: Tue, 8 Jul 2003 22:38:14 -0700 Lines: 48 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 204.200.27.7 Message-ID: <3f0baa44$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1057729092 204.200.27.7 (8 Jul 2003 22:38:12 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail