Finding out if a given character is in UpperCase, LowerCase or Numeric
|
|
Thread rating:  |
fenila11 - 30 Jun 2008 10:30 GMT Hi,
I wanted to know if there is some process in vb to find out if a given character is in UpperCase, LowerCase or Numeric.
Please let me know
Jan Hyde (VB MVP) - 30 Jun 2008 13:03 GMT "fenila11" <u44579@uwe>'s wild thoughts were released on Mon, 30 Jun 2008 09:30:52 GMT bearing the following fruit:
>Hi, > >I wanted to know if there is some process in vb to find out if a given >character is in UpperCase, LowerCase or Numeric. > >Please let me know Yes there is.
There are many ways, but you might want to start my reading up on asc,Ucase,Lcase,Val
-- Jan Hyde
https://mvp.support.microsoft.com/profile/Jan.Hyde
Norm Cook - 30 Jun 2008 13:38 GMT > Hi, > > I wanted to know if there is some process in vb to find out if a given > character is in UpperCase, LowerCase or Numeric. > > Please let me know Look up the Asc() and Chr$() functions in the help.
'this will give a quick dump of the printable ascii chart Private Sub Form_Load() Dim i As Long For i = 32 To 126 Step 2 Debug.Print i, Chr$(i), i + 1, Chr$(i + 1) Next End Sub
Sinna - 30 Jun 2008 15:42 GMT > Hi, > > I wanted to know if there is some process in vb to find out if a given > character is in UpperCase, LowerCase or Numeric. > > Please let me know I suppose you're only talking about the Western Character sets (ANSI/ASCII).
In that case: <code> Dim c As String
Select Case Asc(c) Case Asc("0") To Asc("9"): Debug.Print "Numeric" Case Asc("A") To Asc("Z"): Debug.Print "Uppercase" Case Asc("a") To Asc("z"): Debug.Print "Lowercase" Case Else: Debug.Print "(not covered)" End Select </code>
To let the it work, c should only contain 1 character.
Hope this helps however I get the feeling I'm doing someones homework here...
Sinna
Rick Rothstein (MVP - VB) - 01 Jul 2008 09:15 GMT > Hope this helps however I get the feeling I'm doing someones > homework here... I had the same feeling which is why I gave my Like operator solution... at the point the OP's question might be asked in a class, I don't think the instructor would have covered the Like operator yet (if at all). Then, of course, given that few schools are probably teaching VB6 any more, there is a good chance this was a legitimate question.
Rick
Rick Rothstein (MVP - VB) - 01 Jul 2008 09:10 GMT > I wanted to know if there is some process in vb to find out if a given > character is in UpperCase, LowerCase or Numeric. Try this function out...
Function CharacterType(Char As String) As String If Char Like "[A-Z]" Then CharacterType = "Upper Case" ElseIf Char Like "[a-z]" Then CharacterType = "Lower Case" ElseIf Char Like "#" Then CharacterType = "Digit" Else CharacterType = "Not Alpha-Numeric" End If End Sub
Rick
Sinna - 03 Jul 2008 07:31 GMT >> I wanted to know if there is some process in vb to find out if a given >> character is in UpperCase, LowerCase or Numeric. [quoted text clipped - 14 lines] > > Rick I seldom use the Like operator. In this case it's very readable, but in most cases (where the strength of the operator is revealed) it's hardly readable what it does in fact.
Sinna
Rick Rothstein (MVP - VB) - 03 Jul 2008 10:27 GMT >>> I wanted to know if there is some process in vb to find out if a given >>> character is in UpperCase, LowerCase or Numeric. [quoted text clipped - 16 lines] > most cases (where the strength of the operator is revealed) it's hardly > readable what it does in fact. Then you would definitely **not** like (no pun intended) Regular Expressions... the Like operator is like (again, no pun intended<g>) an **extremely** watered down Regular Expression evaluator. Me, I like Like.<g>
Rick
Tony Proctor - 01 Jul 2008 12:04 GMT Being pedantic, most of the replies to your question are not totally accurate. If all you're interested in is A-Z and a-z then they'll do. However, be aware that other languages based on the Latin alphabet may have diacritical marks (aka accents) and so simply looking at A-Z will not work.
For instance, consider A with an acute accent. Chr$(193) is the uppercase and Chr$(225) is the lowercase.
Maybe a better test for lowercase would be...
If sText = LCase$(sText) Then Debug.Print "Lower case!!" End If
What are you trying to achieve at the end of the day?
Tony Proctor
> Hi, > > I wanted to know if there is some process in vb to find out if a given > character is in UpperCase, LowerCase or Numeric. > > Please let me know Sinna - 02 Jul 2008 07:30 GMT > Being pedantic, most of the replies to your question are not totally > accurate. If all you're interested in is A-Z and a-z then they'll do. [quoted text clipped - 3 lines] > For instance, consider A with an acute accent. Chr$(193) is the uppercase > and Chr$(225) is the lowercase. That's why I stated in my reply that I was only covering ANSI/ASCII. Now I read your reply, I should have said: ASCII-7.
Sinna
Tony Proctor - 02 Jul 2008 10:44 GMT I shouldn't worry Sinna. I'm sure the OP wasn't really interested in worldwide distribution :-)
I always try to bring the subject up whenever I can, though, just to remind people. The majority of applications written in the Western world are not globally aware, and it doesn't make any difference whether the programming language uses Unicode, or offers locale-aware support. I've been involved in international projects for 20 years and developers always make the same mistakes or assumptions. :-(
It's not just a matter of character sets, or alphabets (as in this case), or decimal-point/triple-point characters, or date representations, or boolean representations, etc. There are fundamental differences at the local language level such as how the sentences are put together (affects parameter placement, for instance), or the concept of plurals, or the concept of masculine/feminine, etc. Even writing English language s/w for UK and US distribution should consider such differences, although it rarely does
Ah well, back to work, eh?
Tony Proctor
>> Being pedantic, most of the replies to your question are not totally >> accurate. If all you're interested in is A-Z and a-z then they'll do. [quoted text clipped - 8 lines] > > Sinna Sinna - 03 Jul 2008 07:30 GMT > I shouldn't worry Sinna. I'm sure the OP wasn't really interested in > worldwide distribution :-) [quoted text clipped - 30 lines] >> >> Sinna Well, most examples I find on the Internet don't cover Unicode at all, especially when calling APIs. Before I had to introduce Japanese language support in my application, I didn't either, but since then, I always try to use the W-variant of the API (if available). I don't have to deal with the A-variant anymore as the 'oldest' OS my application supports is Win2k. Fact is that calling the W-variants is quite a lot harder to implement (and so to read as newbee).
Sinna
Tony Proctor - 03 Jul 2008 09:59 GMT The 'A' versions work with Japanese, etc., too Sinna. However, the "ANSI character set" being used is different in different locales. The main advantage of using Unicode data and support is that the interpretation of the data is unambiguous, and not subject to misinterpretation when moving it from one place to another
Tony Proctor
>> I shouldn't worry Sinna. I'm sure the OP wasn't really interested in >> worldwide distribution :-) [quoted text clipped - 42 lines] > > Sinna Sinna - 07 Jul 2008 07:56 GMT > The 'A' versions work with Japanese, etc., too Sinna. However, the "ANSI > character set" being used is different in different locales. The main [quoted text clipped - 3 lines] > > Tony Proctor I know, but when using strings, it's very hard to get the correct locale / codepage to get things working. When switching to the Wide-variant, there's no such hassle...
BTW: The moving is in fact the main issue here!
Sinna
|
|
|