473,387 Members | 1,497 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,387 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 9445
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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.