Hello,
is there any function to check, if a string contains ASCII Chars (a-z) only?
Something like
ret = IsAscii(buf)
e.g.:
"abcdef" ---> @TRUE
"abc-ef" ---> @FALSE
To be a bit pedantic but clear, ASCII characters are more than a-z. I do not believe there is a function that will do what you require. Here is one option. It only does the lower case as you have indicated. If you want upper you should be able to adjust. You could also use StrClean() and compare sizes as another option.
Jim
#DefineFunction IsASCII(str)
arr = ArrayFromStr(str)
ForEach a in arr
If Char2Num(a) < 97 || Char2Num(a) > 122 Then Return @FALSE
Next
Return @TRUE
#EndFunction
str = "abcd"
Message("ASCII?",IsASCII(str))
str = "Abcd"
Message("ASCII?",IsASCII(str))
str = "ab,d"
Message("ASCII?",IsASCII(str))
It isn't as intuitive as Jim's example but you can also use the StrTypeInfo function.
https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILLZ_S__050.htm
str = 'abcDe'
Type = StrTypeInfo(str, 1) ^ 128 ; Remove the hex digit bit.
; Allow both upper and lower case apha characters.
if type == 771 || type == 770 then Text = "is ASCII"
else text = "is not all ASCII"
Message(str, text)
There is also sillycode
gosub udfs
ascii = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
str = "abcd"
isascii()
str = "Abcd"
isascii()
str = "ab,d"
isascii()
:udfs
#DefineSubRoutine isascii()
n = StrLen(str)
ret= "is Ascii"
For j = 1 To n
if StrIndex(ascii,StrUpper(StrSub(str,j,1)),1,@FWDSCAN)==0 Then ret="is not Ascii"
Next
Message(str,ret)
#EndSubRoutine
Return
Nice. Not sure I recall seeing that function before. Thanks.
Jim
Quote from: td on November 24, 2025, 10:53:48 AMIt isn't as intuitive as Jim's example but you can also use the StrTypeInfo function.
https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILLZ_S__050.htm
str = 'abcDe'
Type = StrTypeInfo(str, 1) ^ 128 ; Remove the hex digit bit.
; Allow both upper and lower case apha characters.
if type == 771 || type == 770 then Text = "is ASCII"
else text = "is not all ASCII"
Message(str, text)
many thanks for the answers.
The second line of the script I posted should be
Type = StrTypeInfo(str, 1) & (~128) ; Remove the hex digit bit.