Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6765615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:43:58+00:00 2026-05-26T14:43:58+00:00

I am using data that involves Chinese Unihan characters in an Objective-C app. I

  • 0

I am using data that involves Chinese Unihan characters in an Objective-C app. I am using a voice recognition program (cmusphinx) that returns a phrase from my data. It returns UTF-8 characters and when returning a Chinese character (which is three bytes) it separates it into three separate characters.
Example: When I want 人 to, I see: ‰∫∫. This is the proper in coding (E4 BA BA), but my code sees the returned value as three seperate characters rather than one.

Actually, my function is receiving the phrase as an NSString, (due to a wrap around) which uses UTF-16. I tried using Objective-C’s built in conversion methods (to UTF-8 and from UTF-16), but these keep my string as three characters.

How can I decode these three separate characters into the one utf-8 codepoint for the Chinese character?

Or how can I properly encode it?
This is code fragment dealing with the cstring returned from sphinx and its encoding to a NSString:

const char * hypothesis = ps_get_hyp(pocketSphinxDecoder, &recognitionScore, &utteranceID);
NSString *hypothesisString = [[NSString alloc] initWithCString:hypothesis encoding:NSMacOSRomanEncoding];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:43:59+00:00Added an answer on May 26, 2026 at 2:43 pm

    Edit: From looking at the addition to your post, you actually do have control over the string encoding. In that case, why are you creating the string with NSMacOSRomanEncoding when you’re expecting utf-8? Just change that to NSUTF8StringEncoding.


    It sounds like what you’re saying is you’re being given an NSString that contains UTF-8 data that’s being interpreted as a single-byte encoding (e.g. ISO-Latin-1, MacRoman, etc). I’m assuming here that you have no control over the code that creates the NSString, because if you did then the solution is just to change the encoding it’s initializing with.

    In any case, what you’re asking for is a way to take the data in the string and convert it back to UTF-8. You can do this by creating an NSData from the NSString using whatever encoding its was originally created with (you need to know this much, at least, or it won’t work), and then you can create a new NSString from the same data using UTF-8.

    From the example character you gave (人) it looks like it’s being interpreted as MacRoman, so lets go with that. The following code should convert it back:

    - (NSString *)fixEncodingOfString:(NSString *)input {
        CFStringEncoding cfEncoding = kCFStringEncodingMacRoman;
        NSStringEncoding encoding = CFStringCovnertEncodingToNSStringEncoding(cfEncoding);
        NSData *data = [input dataUsingEncoding:encoding];
        if (!data) {
            // the string wasn't actually in MacRoman
            return nil;
        }
        NSString *output = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that SQL Server endpoint returns data using SOAP. Does anyone know if
So I'm working on app that involves leveraging user profile data from FB. But
I'm working on an assignment that involves writing a program to process data (calculate
I have just started a project that involves me sending data using POST in
I am posting some data using ajax. I want to manipulate that data and
I am using a hardware interface to send data that requires me to set
I have a range of data that I have approximated using a polynomial of
I have two NSTableViews populated with Core Data that are linked using bindings. When
What is the best way to store data that is dynamic in nature using
I am making a 2D game in javascript/ajax, that will be using data stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.