473,242 Members | 1,473 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,242 software developers and data experts.

compare 2 string

I have 2 strings

name1 = 'john smith'

name2 = 'John smith'

What command should I use to check whether name2 is a capitalized version of name1? (the return value is True)
Sep 14 '07 #1
3 9441
bvdet
2,851 Expert Mod 2GB
I have 2 strings

name1 = 'john smith'

name2 = 'John smith'

What command should I use to check whether name2 is a capitalized version of name1? (the return value is True)
Expand|Select|Wrap|Line Numbers
  1. >>> name1 = 'john smith'
  2. >>> name2 = 'John smith'
  3. >>> name1.lower() == name2.lower()
  4. True
  5. >>> import string
  6. >>> name2[0] in string.ascii_uppercase
  7. True
  8. >>> 
HTH
Sep 14 '07 #2
Expand|Select|Wrap|Line Numbers
  1. >>> name1 = 'john smith'
  2. >>> name2 = 'John smith'
  3. >>> name1.lower() == name2.lower()
  4. True
  5. >>> import string
  6. >>> name2[0] in string.ascii_uppercase
  7. True
  8. >>> 
HTH
Thank you very much. I figured out just a few hours ago.
Expand|Select|Wrap|Line Numbers
  1. name2==name1.capitalize()
  2.  
Very simple but I am an absolute beginner +_+
Sep 14 '07 #3
bartonc
6,596 Expert 4TB
Thank you very much. I figured out just a few hours ago.
Expand|Select|Wrap|Line Numbers
  1. name2==name1.capitalize()
  2.  
Very simple but I am an absolute beginner +_+
Yep. That's the way I went, too. But looking at bvdet's example, I see that it does a far more complete job of making sure that the case of all the letters are the same.
Sep 14 '07 #4

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

Similar topics

3
by: Matt | last post by:
if (123 > 33) will return true and if ("123" > 33) will return true So my question is, if the above behaviors are the same?? If string is a number, and compare with another number, it will...
10
by: tvn007 | last post by:
#include <iostream> #include <string> int main (void){ using namespace std; string STR =("TEST"); const std::string::size_type STR_SIZE = STR.size(); int count =0; while ( count <=...
2
by: kw_uh97 | last post by:
Hello everone, I am a newbie and I have a recordset that returns the values XXXXMain XXXX1 XXXX2 XXXX3 XXXX4 XXXX5 XXXX6 YYYY1
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
1
by: swapnilladhe | last post by:
Hi, I have a array of string and a variable containing string and i code like as; if(String.compare(DFArray,checkBox.name)==0) { alert("R U HERE?"); f=false; ...
3
by: johnhelen | last post by:
Hello I have string of time like this 2007/09/19 18:55:14 Also i have a timestamp field in a postgres database with timezone like this 2004-10-19 10:23:54+02
7
pureenhanoi
by: pureenhanoi | last post by:
Hi bro! Can anyone tell me, how to compare two strings like Operating System compare file names. Example: if i have two string "T*.DOC" and "TIET1.DOC". The comparision operator must return TRUE...
7
by: sigava77 via AccessMonster.com | last post by:
Hi, I have a table with a string field that can store numeric field. How do I make a query to compare this field with a numeric value. Example: Select * from table1 where field1="condition" and...
4
by: ndoe | last post by:
how to compare string in file i mean compare that string content digit or alphabet,and 1 question more can we count that line if first line variable = 1,if read second line variable = 2 and so on...
6
by: webmaniac | last post by:
Hi, does anyone know, How to compare characters in 2 string & return How many characters match in both String. Like the First string is: "Hello World" And second is "This is a Word" So the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.