×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    101

    unicode char comparison

    I'd like to compare a user input char to a unicode char. My code is failing. How to fix? For example:

    Code:
    from appuifw import *
    p = query(u'enter', 'text')  # user inputs £ using the chr key on the phone
    if p == u'£' or p == '£':
        note(u'match')
    Does not result in a match. How do I do the comparison so that it works?

    PyS60 1.9.7

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: unicode char comparison

    Quote Originally Posted by foosion View Post
    I'd like to compare a user input char to a unicode char. My code is failing. How to fix? For example:

    Code:
    from appuifw import *
    p = query(u'enter', 'text')  # user inputs £ using the chr key on the phone
    if p == u'£' or p == '£':
        note(u'match')
    Does not result in a match. How do I do the comparison so that it works?

    PyS60 1.9.7
    hello foosion

    can you tell me what sort of error you are getting, the script above seems perfect.

    Regards,

  3. #3
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    101

    Re: unicode char comparison

    I'm not getting any errors, it's just that the program does not recognize the input pound char as equal to the pound char in the program.

    I suspect it's for reasons similar to those covered in this: http://stackoverflow.com/questions/4...ings-in-python but I can't figure out how to get it to work in PyS60

  4. #4
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: unicode char comparison

    Try this.

    if char == u"\u00a3": # Unicode Character 'POUND SIGN' (U+00A3)
    print "match"




    Or, configure your editor to use utf-8, and use corresponding encoding header at the start of the python file. Then write normally using string literals. (u"€" etc). More info: http://www.amk.ca/python/howto/unicode and http://www.joelonsoftware.com/articles/Unicode.html

  5. #5
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    101

    Re: unicode char comparison

    Code:
    from appuifw import *
    p = query(u'enter', 'text')  # user inputs £ or € using the chr key on the phone
    if p == u'\u00a3':
        note(u'pound')
    elif p == u'\u20ac':
        note(u'euro')
    else:
        note(u'neither')
    actually works

    thanks
    Last edited by foosion; 2009-11-02 at 20:22.

Similar Threads

  1. SyncML , OBEX over Bluetooth
    By pvsasidhar in forum OMA DM/DS/CP
    Replies: 185
    Last Post: 2011-04-04, 14:05
  2. need urgent help on displaying hindi unicode char
    By H_unicode in forum Symbian User Interface
    Replies: 1
    Last Post: 2005-12-28, 06:25
  3. socket read hangs until socket is closed
    By camroe in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-07-21, 09:44
  4. Fonts and range of Unicode char supported
    By achandra1 in forum Symbian
    Replies: 0
    Last Post: 2002-09-23, 10:38
  5. Unicode support FAQ?
    By vaizki in forum General Messaging
    Replies: 1
    Last Post: 2002-07-22, 11:16

Posting Permissions

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