×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2008
    Location
    Russia, Samara
    Posts
    47

    unicode -> ascii

    Hi all!
    How to convert unicode string to ascii string or byte array?

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: unicode -> ascii

    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
    Join Date
    Feb 2008
    Location
    Russia, Samara
    Posts
    47

    Re: unicode -> ascii

    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
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: unicode -> ascii

    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
    Join Date
    Feb 2008
    Location
    Russia, Samara
    Posts
    47

    Re: unicode -> ascii

    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
    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
  •  
×