Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User Red Falcon's Avatar
    Join Date
    Feb 2008
    Location
    Russia, Samara
    Posts
    47
    Hi all!
    How to convert unicode string to ascii string or byte array?

  2. #2
    Nokia Developer Moderator petrib's Avatar
    Join Date
    Mar 2003
    Posts
    9,413
    It depends...

    1) What Unicode encoding (UTF-8, UTF-16/UCS-2 or something else) is used for the Unicode string

    2) What actual data (characters) is contained (anything other characters that are not corresponding to the ASCII values of 0-127 cannot be converted; or you have to replace them with some other character that exists in ASCII, and thus loosing data/information.

    In the simplest conversion, you'd just discard every Unicode character, except those where the first byte is zero and the second byte has a value of 0-127. Anything where the first byte is more than 0, and the second byte is 128 or larger has no ASCII representation. You can also replace those with some other valid ASCII character.

    Read this for an intro on Unicode and various encodings:

    http://www.joelonsoftware.com/printe...s/Unicode.html

  3. #3
    Registered User Red Falcon's Avatar
    Join Date
    Feb 2008
    Location
    Russia, Samara
    Posts
    47
    1)UTF-8 I think
    2)My midlet's user enter a string using his own language. I must include this string in url. Somthing like this:

    "host.com?name="+strUserName

    As I told, strUserName can be any language.

  4. #4
    Nokia Developer Moderator petrib's Avatar
    Join Date
    Mar 2003
    Posts
    9,413
    Then you shouldn't convert the user-supplied entered string to ASCII, because you don't know whether that's doable or not.

    Just use URL encoding and let the server/host handle it.

    Here's a wiki article about that:

    http://wiki.forum.nokia.com/index.ph...in_Java_ME_%3F

  5. #5
    Registered User Red Falcon's Avatar
    Join Date
    Feb 2008
    Location
    Russia, Samara
    Posts
    47
    I have made some changes, and now this is what I realy need! Thanks a lot!

    About changes I made: I add coding for slash symbol:

    ....
    } else if(ch == '\\') {
    sbuf.append("%5C");
    }
    .....

Similar Threads

  1. string -> hex -> ascii
    By manmli in forum Symbian C++
    Replies: 5
    Last Post: 2005-05-02, 22:12
  2. Replies: 1
    Last Post: 2003-12-08, 22:42
  3. Has Nokia broken 7650 J2ME in v4.39?
    By LongSteve in forum Mobile Java General
    Replies: 6
    Last Post: 2003-06-03, 17:05
  4. Replies: 5
    Last Post: 2003-02-07, 11:25
  5. 7650 and MS Bluetooth Transceiver
    By damnedi in forum Bluetooth Technology
    Replies: 1
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved