Attribute VB_Name = "basStringTypes" ' The GetStringType* APIs return information from the Unicode ' property database for each character in the string. Each ctype ' is explained in the CharTypes enum (text from the Platform SDK ' documentation from Microsoft). ' ALSO NEEDS the following modules from the book's CD: ' basLcidCp ' basOSDetection Option Compare Binary Option Explicit ' Character Type Flags. Public Enum CT_ CT_CTYPE1 = &H1 ' ctype 1 information CT_CTYPE2 = &H2 ' ctype 2 information CT_CTYPE3 = &H4 ' ctype 3 information End Enum Public Enum CharTypes ' CType 1 Flag Bits. ' These types support ANSI C and POSIX (LC_CTYPE) character-typing functions. ' A bitwise-OR of these values is returned in the array pointed to by the lpCharType ' parameter when the dwInfoType parameter is set to CT_CTYPE1. For DBCS locales, ' the Ctype 1 attributes apply to both narrow characters and wide characters. The ' Japanese hiragana and katakana characters, and the kanji ideograph characters all ' have the C1_ALPHA attribute. C1_UPPER = &H1 ' upper case C1_LOWER = &H2 ' lower case C1_DIGIT = &H4 ' decimal digits C1_SPACE = &H8 ' spacing characters C1_PUNCT = &H10 ' punctuation characters C1_CNTRL = &H20 ' control characters C1_BLANK = &H40 ' blank characters C1_XDIGIT = &H80 ' other digits C1_ALPHA = &H100 ' any linguistic character ' CType 2 Flag Bits. ' These types support proper layout of Unicode text. For DBCS locales, Ctype 2 applies ' to both narrow and wide characters. The direction attributes are assigned so that ' the bidirectional layout algorithm standardized by Unicode produces accurate results. ' These types are mutually exclusive. For more information about the use of these ' attributes, see The Unicode Standard: Worldwide Character Encoding, Volumes 1 ' and 2, Addison Wesley Publishing Company: 1991, 1992, ISBN 0201567881. C2_LEFTTORIGHT = &H1 ' left to right C2_RIGHTTOLEFT = &H2 ' right to left C2_EUROPENUMBER = &H3 ' European number, digit C2_EUROPESEPARATOR = &H4 ' European numeric separator C2_EUROPETERMINATOR = &H5 ' European numeric terminator C2_ARABICNUMBER = &H6 ' Arabic number C2_COMMONSEPARATOR = &H7 ' common numeric separator C2_BLOCKSEPARATOR = &H8 ' block separator C2_SEGMENTSEPARATOR = &H9 ' segment separator C2_WHITESPACE = &HA ' white space C2_OTHERNEUTRAL = &HB ' other neutrals C2_NOTAPPLICABLE = &H0 ' no implicit directionality ' CType 3 Flag Bits. ' These types are intended to be placeholders for extensions to the POSIX types required ' for general text processing or for the standard C library functions. A bitwise-OR of these ' values is returned when dwInfoType is set to CT_CTYPE3. For DBCS locales, the Cypte 3 ' attributes apply to both narrow characters and wide characters. The Japanese hiragana ' and katakana characters, and the kanji ideograph characters all have the C3_ALPHA ' attribute. C3_NONSPACING = &H1 ' nonspacing character C3_DIACRITIC = &H2 ' diacritic mark C3_VOWELMARK = &H4 ' vowel mark C3_SYMBOL = &H8 ' symbols C3_KATAKANA = &H10 ' katakana character C3_HIRAGANA = &H20 ' hiragana character C3_HALFWIDTH = &H40 ' half width character C3_FULLWIDTH = &H80 ' full width character C3_IDEOGRAPH = &H100 ' ideographic character C3_KASHIDA = &H200 ' Arabic kashida character C3_LEXICAL = &H400 ' lexical character C3_ALPHA = &H8000 ' any linguistic char (C1_ALPHA) C3_NOTAPPLICABLE = &H0 ' ctype 3 is not applicable End Enum Private Declare Function GetStringTypeA Lib "kernel32" ( _ ByVal lcid As Long, _ ByVal dwInfoType As Long, _ ByVal lpSrcStr As String, _ ByVal cchSrc As Long, _ lpCharType As Integer _ ) As Long Private Declare Function GetStringTypeW Lib "kernel32" ( _ ByVal dwInfoType As Long, _ ByVal lpSrcStr As Long, _ ByVal cchSrc As Long, _ lpCharType As Integer _ ) As Long ' Not using these functions, but we could! Private Declare Function GetStringTypeExA Lib "kernel32" ( _ ByVal Locale As Long, _ ByVal dwInfoType As Long, _ ByVal lpSrcStr As String, _ ByVal cchSrc As Long, _ lpCharType As Integer _ ) As Long Private Declare Function GetStringTypeExW Lib "kernel32" ( _ ByVal Locale As Long, _ ByVal dwInfoType As Long, _ ByVal lpSrcStr As Long, _ ByVal cchSrc As Long, _ lpCharType As Integer _ ) As Long ' Given a string, with an optional info type and optional lcid, ' will return an array of integers representing the type of each ' character. Check the CharTypes enum to interpret each ' member of the array. Maybe an example would help: ' TypeOfString("a1@") returns an array of the three characters: ' 386 = &H182 = C1_ALPHA Or C1_XDIGIT Or C1_LOWER ' 132 = &H84 = C1_XDIGIT Or C1_DIGIT ' 16 = &H10 = C1_PUNCT ' Note that the lcid parameter has no purpose on NT/Win2000 as ' it is ignored there, but on Win9x it is used to derive the code page ' for converting the string to Unicode. Public Function TypeOfString( _ st As String, _ Optional InfoType As CT_ = CT_CTYPE1, _ Optional lcid As Long = LANG_USER_DEFAULT _ ) As Integer() Dim rgchtype() As Integer Dim retval As Long ReDim rgchtype(1 To Len(st)) If FOnWindowsNT() Then retval = GetStringTypeW(InfoType, StrPtr(st), Len(st), rgchtype(1)) Else retval = GetStringTypeA(lcid, InfoType, StrPtr(st), Len(st), rgchtype(1)) End If TypeOfString = rgchtype() End Function