Check if first char of a word is uppercase?

U

unba1300

Guest
Hello,

Could someone please tell me if there is an easy way to check in code if the first character of a string was entered as uppercase or not? I don't want to convert it - just check it.

Thanks.
 

Woinowski

Active Member
Licensed User
Longtime User
There might be an easier solution, but this should work

B4X:
' s is your string
Dim first as String
first = s.Substring2(0,1)
If first.ToUpperCase = first then
  ' Here we are
end if
 
Upvote 0
U

unba1300

Guest
Thanks for your very quick reply. Your solution set me in the right direction again.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you are looking for an alternate, here it is:
B4X:
   txt="Basic4Android"
   If Asc(txt) >= 65 AND  Asc(txt)  <= 90 Then  '65 is A, 90 is Z
      Msgbox(txt & " starts with an upper case letter.","")
   Else
      Msgbox(txt & " starts with a lower case letter or something else.","")
   End If
 
Upvote 0

Woinowski

Active Member
Licensed User
Longtime User
Using ASC Value might be problematic

Android (and B4A) use UniCode, as far as I understand it. Restricting that check to ASCII might miss something.
 
Upvote 0
Top