IsUnicodeText Function  
 
BOOL WINAPI IsUnicodeText(
  LPCTSTR lpString,  
  INT nLength  
);

The IsUnicodeText function checks if a string contains valid Unicode characters.

Parameters

lpString
A pointer to a null terminated string. This parameter cannot be NULL.
nLength
An integer value which specifies the number of characters to check. If this value is -1, the length of the string is determined by counting the number of characters up to the terminating null character. This parameter cannot be zero.

Return Value

A non-zero value is returned if the string contains valid Unicode characters. A zero value indicates the string contains characters that are not valid Unicode, or the string does not contain any Unicode characters.

Remarks

There are two versions of this function, IsUnicodeTextA which checks a multi-byte string to ensure that it contains valid UTF-8 encoded text, and IsUnicodeTextW which checks a wide string to ensure it contains valid UTF-16 text.

If the value of the nLength parameter is larger than the number of characters in the string, the function will not check beyond the terminating null character. If the length of the string is unknown, specify a length of -1 and the function will check the entire contents of the string up to the terminating null character.

If there is a byte order mark (BOM) sequence at the beginning of the string, this will be recognized by the function. A string that contains a valid BOM sequence with no corresponding text will be successfully validated by this function.

This function does not perform checks to ensure the string contains printable characters. It only validates that the Unicode string is structurally valid. The IsUnicodeTextA function will check to make sure there are no invalid UTF-8 encodings. The IsUnicodeTextW function will check to make sure the UTF-16 string does not contain any unpaired surrogates.

This function does not preserve state information and cannot be used to check the validity of a stream of text or binary data. It should only be used to validate complete Unicode strings that are terminated with a null character.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: csncdv11.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

UnicodeDecodeText, UnicodeEncodeText