By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,677 Members | 1,882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,677 IT Pros & Developers. It's quick & easy.

How can I check if a letter in a string is upper case or lower case ?

P: n/a
In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has lowercase z
(z2003).
After I read the line, I would like to find out if the 2nd item in the line
(after NQ) has small letter or uppercase. How can I do that ?

Thanks.
Apr 4 '07 #1
Share this Question
Share on Google+
14 Replies


P: n/a
There are a number of ways to do this, but here is a simple one if you
always know which particular char. you want to check:

Dim x As String = "NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5"
Select Case right(left(x,4),1)
Case "z"
'do something
Case "Z"
'do something else
End Select
"fniles" <fn****@pfmail.comwrote in message
news:e7***************@TK2MSFTNGP06.phx.gbl...
In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has lowercase
z (z2003).
After I read the line, I would like to find out if the 2nd item in the
line (after NQ) has small letter or uppercase. How can I do that ?

Thanks.


Apr 4 '07 #2

P: n/a
>In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
If Char.IsUpper(yourString, charIndex) Then ...
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 4 '07 #3

P: n/a
Thanks.
But, it could be z, it could be f, g, h, j, k, m,n,q,u,v,x.
I am trying to avoid having to do case statement for each one of them.

"Scott M." <s-***@nospam.nospamwrote in message
news:Ok**************@TK2MSFTNGP02.phx.gbl...
There are a number of ways to do this, but here is a simple one if you
always know which particular char. you want to check:

Dim x As String = "NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5"
Select Case right(left(x,4),1)
Case "z"
'do something
Case "Z"
'do something else
End Select
"fniles" <fn****@pfmail.comwrote in message
news:e7***************@TK2MSFTNGP06.phx.gbl...
>In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has
lowercase z (z2003).
After I read the line, I would like to find out if the 2nd item in the
line (after NQ) has small letter or uppercase. How can I do that ?

Thanks.



Apr 4 '07 #4

P: n/a
On Apr 4, 2:52 pm, "fniles" <fni...@pfmail.comwrote:
In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has lowercase z
(z2003).
After I read the line, I would like to find out if the 2nd item in the line
(after NQ) has small letter or uppercase. How can I do that ?

Thanks.
You could use the .ToUpper and the .ToLower methods.

if val = val.ToUpper then ' string is upper case

if val = val.ToLower then ' string is lower case

Apr 4 '07 #5

P: n/a
On Apr 4, 4:00 pm, z...@construction-imaging.com wrote:
On Apr 4, 2:52 pm, "fniles" <fni...@pfmail.comwrote:
In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191
Notice the 1st line has uppercase Z (Z2003) and the 2nd line has lowercase z
(z2003).
After I read the line, I would like to find out if the 2nd item in the line
(after NQ) has small letter or uppercase. How can I do that ?
Thanks.

You could use the .ToUpper and the .ToLower methods.

if val = val.ToUpper then ' string is upper case

if val = val.ToLower then ' string is lower case
And in your specific case, use the .SubString method to pick off the
character you need to check,

if val.substring(3, 1) = val.substring(3, 1).tolower then ' is lower
case

Apr 4 '07 #6

P: n/a
Hello fniles,

You can check with the following routine:

Private Function IsUpper(ByVal Value As String) As Boolean
Return (Value = Value.ToUpper)
End Sub

Just give it the letter and it will tell you...

If IsUpper(Strings.Mid(MyLine,4,1)) = True Then
MsgBox ("Is UpperCase")
Else
MsgBox ("Is LowerCase")
End If

Best regards,

Martin

fniles wrote:
In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has lowercase z
(z2003).
After I read the line, I would like to find out if the 2nd item in the line
(after NQ) has small letter or uppercase. How can I do that ?

Thanks.

Apr 4 '07 #7

P: n/a
Just to re-work some of your code to be more .NET Friendly :):

Private Function IsUpper(ByVal Value As String) As Boolean
Return Value = Value.ToUpper
End Sub

Dim theString = "NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5"
If IsUpper(theString.subString(3,1)) Then
MessageBox.Show("Is UpperCase")
Else
MessageBox.Show("Is LowerCase")
End If
"Martin H." <hk***@gmx.netwrote in message
news:46***********************@news.freenet.de...
Hello fniles,

You can check with the following routine:

Private Function IsUpper(ByVal Value As String) As Boolean
Return (Value = Value.ToUpper)
End Sub

Just give it the letter and it will tell you...

If IsUpper(Strings.Mid(MyLine,4,1)) = True Then
MsgBox ("Is UpperCase")
Else
MsgBox ("Is LowerCase")
End If

Best regards,

Martin

fniles wrote:
>In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has
lowercase z (z2003).
After I read the line, I would like to find out if the 2nd item in the
line (after NQ) has small letter or uppercase. How can I do that ?

Thanks.
Apr 4 '07 #8

P: n/a
Nice code Martin,

The Mid is one of the old VB commands I have always prefered, I missed it in
other languages.

Cor

Hello fniles,

You can check with the following routine:

Private Function IsUpper(ByVal Value As String) As Boolean
Return (Value = Value.ToUpper)
End Sub

Just give it the letter and it will tell you...

If IsUpper(Strings.Mid(MyLine,4,1)) = True Then
MsgBox ("Is UpperCase")
Else
MsgBox ("Is LowerCase")
End If

Best regards,

Martin

fniles wrote:
>In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has
lowercase z (z2003).
After I read the line, I would like to find out if the 2nd item in the
line (after NQ) has small letter or uppercase. How can I do that ?

Thanks.
Apr 5 '07 #9

P: n/a
Thank you, all.
I can also use the following:
bMatch = sMonthYear.Substring(0, 1) Like "[A-Z]"
If bMatch Then
'upper case
else
'lower case
end if

"Martin H." <hk***@gmx.netwrote in message
news:46***********************@news.freenet.de...
Hello fniles,

You can check with the following routine:

Private Function IsUpper(ByVal Value As String) As Boolean
Return (Value = Value.ToUpper)
End Sub

Just give it the letter and it will tell you...

If IsUpper(Strings.Mid(MyLine,4,1)) = True Then
MsgBox ("Is UpperCase")
Else
MsgBox ("Is LowerCase")
End If

Best regards,

Martin

fniles wrote:
>In VB.NET 2005 can I check if a letter in a string is upper case or lower
case ?
For example:
I have the following 2 lines:
NQ,Z2003,11/11/2003,1416.5,1420,1402,1411.5
NQ,z2003,11/10/2003,223801,260154
NQ,H2004,11/11/2003,1416.5,1422.5,1406.5,1415
NQ,h2004,11/10/2003,56,1191

Notice the 1st line has uppercase Z (Z2003) and the 2nd line has
lowercase z (z2003).
After I read the line, I would like to find out if the 2nd item in the
line (after NQ) has small letter or uppercase. How can I do that ?

Thanks.
Apr 5 '07 #10

P: n/a
>I can also use the following:
>bMatch = sMonthYear.Substring(0, 1) Like "[A-Z]"
Not if you want your app to work correctly in the rest of the world.
Believe it or not, but there are actually more letters than A - Z.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 5 '07 #11

P: n/a
Mattias,

I never knew that "letter" means in English the same as in "Old Germanic"
languages as Danish and Dutch, I thought that it was in English "character".
While "letter" is what is in our languages "brief" but that is something
quiet different in English.

:-)

Cor

"Mattias Sjögren" <ma********************@mvps.orgschreef in bericht
news:uw*************@TK2MSFTNGP06.phx.gbl...
I can also use the following:
bMatch = sMonthYear.Substring(0, 1) Like "[A-Z]"

Not if you want your app to work correctly in the rest of the world.
Believe it or not, but there are actually more letters than A - Z.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Apr 6 '07 #12

P: n/a
Cor [not sure if you are being facetious],

In English, "character" can mean any character at all, in English or any
other language: alphabetic, numeric, symbol or punctuation. For example,
the ASCII Character Codes are not limited to just alphabetic characters (but
yes, this example is limited to English characters).

"Letter" means just alphabetic characters (English or otherwise) - - A
subset of all characters. Or, it could just mean a document sent via
traditional post.

-Scott
..

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Mattias,

I never knew that "letter" means in English the same as in "Old Germanic"
languages as Danish and Dutch, I thought that it was in English
"character". While "letter" is what is in our languages "brief" but that
is something quiet different in English.

:-)

Cor

"Mattias Sjögren" <ma********************@mvps.orgschreef in bericht
news:uw*************@TK2MSFTNGP06.phx.gbl...
>I can also use the following:
bMatch = sMonthYear.Substring(0, 1) Like "[A-Z]"

Not if you want your app to work correctly in the rest of the world.
Believe it or not, but there are actually more letters than A - Z.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Apr 6 '07 #13

P: n/a

....
Cor [not sure if you are being facetious],
Of course,

However was it facetious, I would not do it in another way to Mattious or
you. I see now that there is in English as well the intent that a letter
can be a single character.

However in my language and I assume the same from Mattias a letter is always
a single character in my idea even when we use it for by instance the Polish
two character letters (I never saw it used as I do here in Dutch). (The
"karakter" exists as well, however less used). Therefore the things I watch
forever is not to write "letter" for a single character, because that error
is easy made.

Thanks for bringing me on the right track with this.

Cor

>
In English, "character" can mean any character at all, in English or any
other language: alphabetic, numeric, symbol or punctuation. For example,
the ASCII Character Codes are not limited to just alphabetic characters
(but yes, this example is limited to English characters).

"Letter" means just alphabetic characters (English or otherwise) - - A
subset of all characters. Or, it could just mean a document sent via
traditional post.

-Scott
.

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>Mattias,

I never knew that "letter" means in English the same as in "Old Germanic"
languages as Danish and Dutch, I thought that it was in English
"character". While "letter" is what is in our languages "brief" but that
is something quiet different in English.

:-)

Cor

"Mattias Sjögren" <ma********************@mvps.orgschreef in bericht
news:uw*************@TK2MSFTNGP06.phx.gbl...
>>I can also use the following:
bMatch = sMonthYear.Substring(0, 1) Like "[A-Z]"

Not if you want your app to work correctly in the rest of the world.
Believe it or not, but there are actually more letters than A - Z.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.



Apr 7 '07 #14

P: n/a
Hmmm, but a "letter" is not just *any* single character, it is an
"alphabetic" single character.
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:e2*************@TK2MSFTNGP02.phx.gbl...
>
...
>Cor [not sure if you are being facetious],

Of course,

However was it facetious, I would not do it in another way to Mattious or
you. I see now that there is in English as well the intent that a letter
can be a single character.

However in my language and I assume the same from Mattias a letter is
always a single character in my idea even when we use it for by instance
the Polish two character letters (I never saw it used as I do here in
Dutch). (The "karakter" exists as well, however less used). Therefore the
things I watch forever is not to write "letter" for a single character,
because that error is easy made.

Thanks for bringing me on the right track with this.

Cor

>>
In English, "character" can mean any character at all, in English or any
other language: alphabetic, numeric, symbol or punctuation. For example,
the ASCII Character Codes are not limited to just alphabetic characters
(but yes, this example is limited to English characters).

"Letter" means just alphabetic characters (English or otherwise) - - A
subset of all characters. Or, it could just mean a document sent via
traditional post.

-Scott
.

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>Mattias,

I never knew that "letter" means in English the same as in "Old
Germanic" languages as Danish and Dutch, I thought that it was in
English "character". While "letter" is what is in our languages "brief"
but that is something quiet different in English.

:-)

Cor

"Mattias Sjögren" <ma********************@mvps.orgschreef in bericht
news:uw*************@TK2MSFTNGP06.phx.gbl...
I can also use the following:
>bMatch = sMonthYear.Substring(0, 1) Like "[A-Z]"

Not if you want your app to work correctly in the rest of the world.
Believe it or not, but there are actually more letters than A - Z.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.




Apr 7 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.