Hello,
How to determine if the text of a TextArea is lowercase or uppercase?
Thanks
Once you have selected the character, use ASC to get its value and you will know…
look the example there:
https://documentation.xojo.com/api/math/asc.html#asc
I extract the first character to see if it’s uppercase or lowercase, but sometimes it’s a number!
if source.Asc >= 65 and source.Asc <= 90 then
MsgBox("UpperCase")
elseif source.Asc >= 97 and source.Asc <= 122 then
MsgBox("LowerCase")
end
You can use the Compare function of the String to do this. The documentation covers it pretty well here.
Here’s a simple function you can add to your project to determine if a string value is uppercase:
Public Function isUppercase(extends value as String) As Boolean
return value.Compare( value.Uppercase, ComparisonOptions.CaseSensitive ) = 0
End Function
Add that a module then call it as:
var result as Boolean = TextArea1.Text.isUppercase
Or
var myString as String = "hElLo"
if myString.isUppercase then
MessageBox( "It's Uppercase!" )
else
MessageBox( "It's not Uppercase!" )
end if
Using that as a starting point and with the help of the documentation, you can create an isLowercase method if you wish.
You do not explain the purpose, so my answer is… generic.
If you explain what you want to do, maybe a different answer can be done…
Do you want to distinguish whether it’s a number or not, or whether it’s uppercase or lowercase? You’ve said either at the same time.