How to Determine If a String Is UNICODE or ANSILast reviewed: October 30, 1995Article ID: Q138142 |
The information in this article applies to:
SUMMARYANSI strings use one byte per character if they don't contain any DBCS characters. UNICODE strings use two bytes per character. There is a built-in OLE API function that allows you determine whether a string is UNICODE or ANSI. However, you can also use the Len() and LenB() Visual Basic functions to compare the length of the string in characters and in bytes, as demonstrated by the step-by-step example in this article. NOTE: The code sample in this article will work only for those cases where you are not likely to encounter DBCS characters in ANSI strings.
MORE INFORMATIONThe Len function returns the length of the string in characters, and the LenB function returns the length of the string in bytes. While this is the same for an ANSI string, LenB will return a value twice that returned by Len for a UNICODE string. This fact can be used to determine if a string is UNICODE or ANSI. NOTE: When a string has been brought into the Visual Basic environment, it will be DBCS if it is the 16-bit version of the product, and UNICODE if it is the 32-bit version of the product. If the string is DBCS, then the string contains characters that are either one or two bytes per character, depending on the contents of the string and the language support in the Operating System. If you do happen to be able to get a 32-bit string that contains the bit patterns for ANSI/DBCS characters, it will be interpreted as UNICODE and produce invalid results when manipulated or used because the UNICODE characters are definitely not what you want.
Step-By-Step Example
|
Additional reference words: 4.00 vb4win vb4all
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |