Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to check caseing in string vb.net

i want to check wheater label text is in
upper case or
lowercase or
title case or
sentence case or
Toggle case

please help!!!

i got soln for lower and upper
i.e
VB
char.isUpper() 
char.isLower()


title case or
sentence case or
Toggle case

still dnt knw how to check
Posted

I don't think there's a one-size-fits-all solution for this. A simple way of determining whether your string IS in that case is to convert it TO that case and then check and see if the converted version is equal to the original. You can reference this article-- Letter Case Conversion Algorithms: Title Case, Toggle Case[^]--which gives some code for title and toggle cases. You could also use the old VB6 StrConv method, which is still available (ProperCase is the same as TitleCase):
VB
Dim s As String = "this is a test"
MessageBox.Show(StrConv(s, VbStrConv.ProperCase))


Note that proper/title case might not quite be what you might want. "A Tale of Two Cities" using the above title/proper case definitions gets you "A Tale Of Two Cities". I'd want that "Of" to be lowercase. A custom, character by character, solution is likely not that complex and will give you finer control of the results.
 
Share this answer
 
isUpper and isLower apply to single characters within a string. I think a better solution is to create a temporary string that is formatted the way you want it and return the comparison.

As an example (for ProperCase)
VB
If String.Format(yourString, vbStrConv.ProperCase) = yourString then
    'your code for proper case
End If 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900