You Are Here:

Community: Developer Discussion Boards

#1 Old how to compare striungs? - 2009-03-04, 18:34

Join Date: Feb 2009
Posts: 11
vijaynag
Offline
Registered User
Hi How to compare strings?

for example ..

I want to compare the first 4 characters of str1 with "abcd"
Reply With Quote

#2 Old Re: how to compare striungs? - 2009-03-04, 19:01

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by vijaynag View Post
Hi How to compare strings?

for example ..

I want to compare the first 4 characters of str1 with "abcd"
Sorry, can you explain better your question?

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
Hope it helps,

Rafael.
Reply With Quote

#3 Old Re: how to compare striungs? - 2009-03-05, 09:54

Join Date: Dec 2007
Posts: 409
Location: Tempe, AZ
Send a message via Yahoo to shubhendra Send a message via Skype™ to shubhendra
shubhendra's Avatar
shubhendra
Offline
Forum Nokia Champion
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.
Reply With Quote

#4 Old Re: how to compare striungs? - 2009-03-05, 10:51

Join Date: Feb 2009
Posts: 11
vijaynag
Offline
Registered User
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
Reply With Quote

#5 Old Smile Re: how to compare striungs? - 2009-03-05, 11:40

Join Date: Jul 2008
Posts: 471
Location: Pakistan
sajisoft's Avatar
sajisoft
Offline
Regular Contributor
Quote:
Originally Posted by vijaynag View Post
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
I love to write source code, to help my friends :P. So , try this
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"
Hope it helps u..

Best Regards,
SajiSoft


"The purpose of software engineering is to control complexity, not to create it."

--§ajid Ali Anjum--
http://sajisoft.wordpress.com/
Reply With Quote

#6 Old Re: how to compare striungs? - 2009-03-05, 17:35

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
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"
Hope it helps,

Rafael.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia