What is the best way to determine if a character is a letter in VB6?

We need a function that takes a character as a parameter and returns true if it is a letter.

+3
source share
9 answers

Seanyboy's IsCharAlphaA answer is close. The best way is to use the W version like this:

Private Declare Function IsCharAlphaW Lib "user32" (ByVal cChar As Integer) As Long
Public Property Get IsLetter(character As String) As Boolean
    IsLetter = IsCharAlphaW(AscW(character))
End Property

Of course, this is all very important, since all VB6 controls have only ANSI

+4
source

This was part of the code posted by rpetrich in response to a question by Joel Spolsky . I felt that he needed a position specific to the problem that she was solving. It is really brilliant.

Private Function IsLetter(ByVal character As String) As Boolean
    IsLetter = UCase$(character) <> LCase$(character)
End Function

: " ?" UCase LCase , :

UCase ; .

LCase ; .

+7
Private Function IsLetter(Char As String) As Boolean
    IsLetter = UCase(Char) Like "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]"
End Function
+2

, ?

Private Function IsLetter(ByVal ch As String) As Boolean
    IsLetter = (ch >= "A" and ch <= "Z") or (ch >= "a" and ch <= "z")
End Function
+1

, . rpetrich , , , . API TCHAR ( WCHAR), Long. , HFFFF. , , Integer Long . , & HFFFF & ?

, UnicoWS API Win9X. , UnicoWS.dll, , , . , , VB6 , Win9X, .

Option Explicit

Private Declare Function IsCharAlphaW Lib "unicows" (ByVal WChar As Integer) As Long

Private Function IsLetter(Character As String) As Boolean
    IsLetter = IsCharAlphaW(AscW(Character))
End Function

Private Sub Main()
    MsgBox IsLetter("^")
    MsgBox IsLetter("A")
    MsgBox IsLetter(ChrW$(&H34F))
    MsgBox IsLetter(ChrW$(&HFEF0))
    MsgBox IsLetter(ChrW$(&HFEFC))
End Sub
+1

, :

Private Declare Function IsCharAlphaA Lib "user32" Alias "IsCharAlphaA" (ByVal cChar As Byte) As Long

I believe IsCharAlphaA checks ANSI character sets and IsCharAlpha ASCII tests. Maybe I'm wrong.

0
source
Private Function IsAlpha(ByVal vChar As String) As Boolean
  Const letters$ = "abcdefghijklmnopqrstuvwxyz"

  If InStr(1, letters, LCase$(vChar)) > 0 Then IsAlpha = True
End Function
0
source

I use this in VBA

Function IsLettersOnly(Value As String) As Boolean
   IsLettersOnly = Len(Value) > 0 And Not UCase(Value) Like "*[!A-Z]*"
End Function
0
source

He definitely does not document himself. And it can be slow. This is a smart hack, but it is. I would have a desire to be more obvious in my test. Either use a regular expression, or write a more obvious test.

public bool IsAlpha(String strToCheck)
{
    Regex objAlphaPattern=new Regex("[^a-zA-Z]");
    return !objAlphaPattern.IsMatch(strToCheck);
}

public bool IsCharAlpha(char chToCheck)
{
    return ((chToCheck=>'a') and (chToCheck<='z')) or ((chToCheck=>'A') and (chToCheck<='Z'))
}
-1
source

Source: https://habr.com/ru/post/1697126/


All Articles