| Reply | « Previous Thread | Next Thread » |
|
Hi How to compare strings?
for example .. I want to compare the first 4 characters of str1 with "abcd" |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
|
Quote:
If you want to check if both strings have same value, use this: Code:
x = "abc" y = "abcd" res = x==y print res # prints True if they are equal and False if don't, in this case, the result is False Rafael. |
|
Maybe it will be better to extract first 4 characters of str1 and then compare them with 'abcd'.
I mean copy the first 4 characters into another string and then you can uses Rafael's code. IDEAS is all they need but still they think only Genius can give them that. |
| shubhendra |
| View Public Profile |
| Find all posts by shubhendra |
|
let me give more details on my question...
l=logs.calls(mode='missed')[0] phno = l["number"] strph = str(phno) if (strph.find("+91") != 0): print "Indian Number" else: print "Other number" The above code is always executing the else part. i.e everytime it prints other number. That is the value of strph.find("+91") is always 0. Can some one help me how to find if the phone number starts with "+919" Thanks, Vijay |
|
Quote:
Code:
import logs
l=logs.calls(mode='missed')[0]
num = l["number"] //it gives number in unicode
if (num[:3] == "+91" or num[:4] == "0091") :
print "India Number"
else :
print "Other number"
Best Regards, SajiSoft "The purpose of software engineering is to control complexity, not to create it." --§ajid Ali Anjum-- http://sajisoft.wordpress.com/ |
|
Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Rafael T.
Offline
Forum Nokia Champion
|
|
You can also use startswith():
Code:
number = "+9193333"
if number.startswith("+919"):
print "The number starts with +919"
else:
print "The number doesn't start with +919"
Rafael. |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| How to compare date Sql Query in Symbian | kamaljaiswal | General Symbian C++ | 2 | 2009-08-31 01:57 |
| how to compare 2 Dates? | rohanwaugh | Symbian User Interface | 4 | 2008-12-12 12:28 |
| how to compare the list items with a string | manojkumar.m | General Symbian C++ | 7 | 2008-11-18 06:32 |
| compare descriptors | ismailc | General Symbian C++ | 1 | 2008-04-07 20:43 |
| How to compare \n characters ? | HidayathKhan | General Symbian C++ | 1 | 2007-11-29 09:57 |