Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 10: Characteristics of a Window's Frame


found in the string, this method returns the position of its first occurrence. If you want the
get the last occurrence of the character, call the ReverseFind() instead. Its syntax is:

int ReverseFind(TCHAR ch) const;

These two versions of the Find() method are used to find a particular character in a
string. Alternatively, you can specify a group of characters and try to find, at least, any
one of them in the string. This operation is performed using the FindOneOf() method. Its
syntax is:

int FindOneOf(LPCTSTR lpszCharSet) const;

The lpszCharSet argument is passed as a string which is a group of characters in any
order. If the compiler finds any character of the lpszCharSet argument in the string, it
returns its position. If none of the lpszCharSet characters is in the string, this method
returns –1.

9.5.4 Character Identification


Every time the user types a character in a text-based control, this is referred to as a
keystroke. When performing data entry, even if the user presses two keys simultaneously
(to enter an uppercase letter or to type a special character), only one character is entered
at a time. You can find out what character the user had entered in your application using
appropriate functions. Some functions are used to categorize the types of characters on
the keyboard. The functions used for these validations are as follows:

Function Meaning
int isalpha(int c); Returns true if c is an alphabetic character. Otherwise, returns false
int islower(int c); Returns true if c is an alphabetic character in lowercase. Otherwise,
returns false.
int isupper(int c); Returns true if c is an alphabetic character in uppercase. Otherwise,
returns false
int isdigit(int c); Returns true if c is a digit. Otherwise, returns false
int isxdigit(int c); Returns true if c is a hexadecimal digit. c must be one of the
following 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, A, B, C, D, E, or
F. Otherwise, returns false.
int isalnum(int c); Returns true is c is between 0 and 9 or if c is between a and z or if c
is between A and Z. Otherwise, returns false.
int isascii(int c); Returns true if c is an ASCII character. Otherwise, returns false
int ispunct(int c); Returns true if c is a punctuation character. Otherwise, returns false.
int isprint(int c); Returns true if c is a printable character. Otherwise, returns false.
int isgraph(int c); Returns true if c is a printable character and is not an empty space.
int isspace(int c); Returns true if c is an empty space

9.5.5 Removing Characters..........................................................................


Besides the CString::SetAt() method, you can also use the Replace() method to replace
a character of the string with another character. The syntax of the Replace() method is:

int Replace(TCHAR chOld, TCHAR chNew);

The Replace() method replaces each occurrence of the chOld argument. Whenever it
finds it, it replaces it with the chNew character.
Free download pdf