An isAlpha function is just one case where you look for all characters being of certain unicode types (either upper or lower were chosen in my original post)
The more general function ContainsOnlyUnicodeTypes below allows search for all characters being of only a chosen unicode type or a chosen array of unicode types
ContainsUnicodeTypes is a general function allowing search for contains at least one character being of a given unicode type or array of unicode types
EDIT: CHANGED FIRST SUB NAME TO LESS CONFUSING ContainsOnlyUnicodeTypes
Edit2: minor correction in test sub descriptions
Code: Select all
Option Explicit
REM ***** BASIC *****
Sub testSub
'''''''ContainsOnlyUnicodeTypes - every character of chosen unicode types
dim UnicodeTypes
'for isalpha choose unicode types upper and lower case
' UnicodeTypes = array(com.sun.star.i18n.UnicodeType.UPPERCASE_LETTER,com.sun.star.i18n.UnicodeType.LOWERCASE_LETTER)
' msgbox ContainsOnlyUnicodeTypes("777ppppp888",UnicodeTypes)
' msgbox ContainsOnlyUnicodeTypes("777ppppp888",UnicodeTypes,3,5)
' msgbox ContainsOnlyUnicodeTypes("777ppppp888",UnicodeTypes,1,5)
' UnicodeTypes = com.sun.star.i18n.UnicodeType.UPPERCASE_LETTER
' msgbox ContainsOnlyUnicodeTypes("777ppppp888",UnicodeTypes)
' msgbox ContainsOnlyUnicodeTypes("PRTUER",UnicodeTypes)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''ContainsUnicodeTypes - contain at least one character of chosen unicode types
' UnicodeTypes = com.sun.star.i18n.UnicodeType.DECIMAL_DIGIT_NUMBER
' msgbox ContainsUnicodeTypes("777ppppp888",UnicodeTypes)
' msgbox ContainsUnicodeTypes("pppppp",UnicodeTypes)
' UnicodeTypes = array(com.sun.star.i18n.UnicodeType.UPPERCASE_LETTER,com.sun.star.i18n.UnicodeType.LOWERCASE_LETTER)
' msgbox ContainsUnicodeTypes("9K832737",UnicodeTypes,1,3)
end sub
function ContainsOnlyUnicodeTypes(st as string,UnicodeTypes,optional zerobasedA as long,optional zerobasedB as long) as boolean
dim n as long, aLocale,i as long,CharClassification,lenst as long,ub as long, j as long, found as boolean,a as long, b as long
CharClassification = createUNOService("com.sun.star.i18n.CharacterClassification")
aLocale = ThisComponent.CharLocale
lenst= len(st)
if lenSt >0 then
if ismissing(zerobasedA) = true then
a=0
b= lenst-1
else
a =zerobasedA
b= zerobasedB
if (a<0 or a >= lenst or b<a or b<0 or b>= lenst) then exit function
end if
if vartype(Unicodetypes) > 8192 then 'array
ub = ubound(Unicodetypes)
ContainsOnlyUnicodeTypes =true
For i = a to b
n = CharClassification.getType(st, i, aLocale)
found = false
for j = 0 to ub
if n= UnicodeTypes(j) then
found = true
exit for
end if
next
if found = false then
ContainsOnlyUnicodeTypes = false
exit for
end if
Next
else
ContainsOnlyUnicodeTypes =true
For i = a to b
n = CharClassification.getType(st, i, aLocale)
if n<> UnicodeTypes then
ContainsOnlyUnicodeTypes = false
exit for
end if
Next
end if
end if
End function
function ContainsUnicodeTypes(st as string,UnicodeTypes,optional zerobasedA as long,optional zerobasedB as long) as boolean
dim n as long, aLocale,i as long,CharClassification,lenst as long,ub as long, j as long,a as long, b as long
CharClassification = createUNOService("com.sun.star.i18n.CharacterClassification")
aLocale = ThisComponent.CharLocale
lenst= len(st)
if lenSt >0 then
if ismissing(zerobasedA) = true then
a=0
b= lenst-1
else
a =zerobasedA
b= zerobasedB
if (a<0 or a >= lenst or b<a or b<0 or b>= lenst) then exit function
end if
if vartype(Unicodetypes) > 8192 then 'array
ub = ubound(Unicodetypes)
For i = a to b
n = CharClassification.getType(st, i, aLocale)
for j = 0 to ub
if n= UnicodeTypes(j) then
ContainsUnicodeTypes = true
exit function
end if
next
Next
else
For i = a to b
n = CharClassification.getType(st, i, aLocale)
if n= UnicodeTypes then
ContainsUnicodeTypes = true
exit for
end if
Next
end if
end if
End function