473,699 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String comparisons

60 New Member
I am making a program that requires me to test whether a certain character in a string is capital. I was wondering if there was anyway I could do this like:

string is A-Z

That would determine whether the string is any letter from A to Z
Aug 20 '07 #1
8 1466
ilikepython
844 Recognized Expert Contributor
I am making a program that requires me to test whether a certain character in a string is capital. I was wondering if there was anyway I could do this like:

string is A-Z

That would determine whether the string is any letter from A to Z
Expand|Select|Wrap|Line Numbers
  1. >>> import string
  2. >>> 'g' in string.lowercase
  3. True
  4. >>> 'D' in string.lowercase
  5. False
  6.  
Aug 20 '07 #2
psychofish25
60 New Member
Expand|Select|Wrap|Line Numbers
  1. >>> import string
  2. >>> 'g' in string.lowercase
  3. True
  4. >>> 'D' in string.lowercase
  5. False
  6.  
Okay thanks, but is there a way to determine whether a letter is a vowel or not?
kinda like string=['a','e','i','o' ,'u']
Aug 20 '07 #3
ilikepython
844 Recognized Expert Contributor
Okay thanks, but is there a way to determine whether a letter is a vowel or not?
kinda like string=['a','e','i','o' ,'u']
Well...
Expand|Select|Wrap|Line Numbers
  1. >>> vowels = "aeiou"
  2. >>> 'e' in vowels
  3. True
  4. >>> 'f' in vowels
  5. False
  6.  
Aug 20 '07 #4
psychofish25
60 New Member
Well...
Expand|Select|Wrap|Line Numbers
  1. >>> vowels = "aeiou"
  2. >>> 'e' in vowels
  3. True
  4. >>> 'f' in vowels
  5. False
  6.  
Okay that makes sense now. But is there anyway to make it like a to z without typing each letter?
Aug 20 '07 #5
bartonc
6,596 Recognized Expert Expert
Okay that makes sense now. But is there anyway to make it like a to z without typing each letter?
Expand|Select|Wrap|Line Numbers
  1. >>> from string import letters
  2. >>> "B" in letters
  3. True
  4. >>> 
Aug 20 '07 #6
psychofish25
60 New Member
Expand|Select|Wrap|Line Numbers
  1. >>> from string import letters
  2. >>> "B" in letters
  3. True
  4. >>> 
Okay excellent, thanks.
Aug 20 '07 #7
ghostdog74
511 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. >>> "B".isupper()
  2. True
  3. >>> "b".isupper()
  4. False
  5. >>> 
  6.  
Aug 20 '07 #8
bartonc
6,596 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. >>> "B".isupper()
  2. True
  3. >>> "b".isupper()
  4. False
  5. >>> 
  6.  
Thanks, GD. Strings do have quite a few handy methods hung on them.
I also meant to point out that the string module is useful for the constants defined there, but the functions which are now string methods should not be used.
Aug 20 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2394
by: Monkey Steve | last post by:
Hi, I'm writing a website in asp.net(vb) with an access database behind it. As part of the site I have a table which has stores maximum and minimum values. These are integers at present. However - I need to change them to strings so that I can store the string "unknown" if these are not known. Problem is that my comparisons >= etc then won't work properly. Because of the way I am using the db I cannot have a pointer value, eg
6
2124
by: Maileen | last post by:
Hi, I have the following code : Function GetRequestType(ByVal EvDt As String, ByVal StPeriod As String, ByVal EdPeriod As String, ByVal TaskType As String) As Integer Dim strtest As String Dim i, j As Integer i = strtest.Compare(EvDt,StPeriod) Select Case (TaskType) Case "Old"
1
2569
by: Dino Buljubasic | last post by:
Hi, I am using lots of string comparisons using String.StartsWith(subString) method where subString might be more than just couple of chars (e.g. "This is the string to compare ") I have noticed that it executes quite slowly. Is there a way to do this faster? tx
4
2995
by: Sjaakie | last post by:
I need to replace parts of a string, in a collection deserialized from an XML file, with values from another collection. Is there another, more clever/faster/better, method than the loops below? TIA foreach (StringObject x in (StringObjectCollection)xc) { foreach (ReplacementStringObject r in
4
23955
by: Mark Rae | last post by:
Hi, Is it possible to create a case-insensitive List<stringcollection? E.g. List<stringMyList = new List<string>; MyList.Add("MyString"); So that:
2
1661
by: Nishad | last post by:
Is anybody know how to write xpath for string Value Comparisons thank you
26
3805
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I test whether a string has a value or not by the following syntax: if (thisString.Trim() == "") {
12
2835
by: Merk | last post by:
What are some alternatives to using .ToUpper() to perform case insensitive string comparisons? The reason I'm asking is that I'm comparing strings in a long loop, looking for equality; and I want for this loop to run as fast as possible. So I'm looking for a method that would be faster than .ToUpper(). Thanks!
14
13488
by: Steve Bergman | last post by:
I'm looking for a module to do fuzzy comparison of strings. I have 2 item master files which are supposed to be identical, but they have thousands of records where the item numbers don't match in various ways. One might include a '-' or have leading zeros, or have a single character missing, or a zero that is typed as a letter 'O'. That kind of thing. These tables currently reside in a mysql database. I was wondering if there is a...
0
10583
NeoPa
by: NeoPa | last post by:
ANSI-89 v ANSI-92 Before we get into all the various types of pattern matching that can be used, there are two ANSI standards used for the main types of wildcard matching (matching zero or more characters or simply matching a single character) : ANSI-89 - Mainly used only by Jet / ACE SQL ANSI-92 - Mainly used by SQL Server and other grown-up products In the later versions of Access it is now possible to select ANSI-92 compatibility as an...
0
8618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9178
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8916
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8885
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7752
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.