473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
14 43716
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
>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
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
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
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
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
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
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
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
>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
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
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

....
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: semovrs | last post by:
Hello, everyone! I would appreciate any input or advice on the following quite simple issue: If I search through a file list using grep -E '.*$' it will not pull files ending in JPG and files...
10
by: David | last post by:
What can I do to accept either uppercase or lower case " y or n" in the program below.? any help will be appreciated #include <iostream> using namespace std; //class definigtion class Pizza...
22
by: DJ | last post by:
Can someone tell me the library call that converts strings to lower case or retrns a new string that is lower case of the original, thanks im using <string> David
9
by: B Williams | last post by:
I have written some code that will take in a string and print out the reverse, but I also want it to check for upper and lower case and swap them. Will someone assist me? include <iostream>...
4
by: silversnake | last post by:
Hi , dose one know the code for checking through a string for upper or lower case char's and reverse them of find ? thanks
5
by: cfmx2008 | last post by:
Hi Guys, I hope you could help me to solve this problem. Here it is: I have a huge table of data. Some data are Lower case and some are upper case. these data could be changed by agents, But I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.