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 7060023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:18:10+00:00 2026-05-28T04:18:10+00:00

I am new to Objective-C and try to convert a malformed UTF8 encoded NSString

  • 0

I am new to Objective-C and try to convert a malformed UTF8 encoded NSString to a wellformed one using the example on apples docs.

NSString *theString = @"Lügen"; //should be "ü"
NSString *asciiString = [[NSString alloc] initWithData:asciiData encoding:NSASCIIStringEncoding];

NSLog(@"Original: %@ (length %d)", theString, [theString length]);  
NSLog(@"Converted: %@ (length %d)", asciiString, [asciiString length]);

Result:

Original: Lügen (length 6)
Converted: LA1/4gen (length 8)

This here is doing nothing:

NSString* str = [NSString stringWithUTF8String:
                 [theString cStringUsingEncoding:NSASCIIStringEncoding]];

This here crashes my app

NSString* str = [NSString stringWithUTF8String:
                 [theString cStringUsingEncoding:NSUTF8StringEncoding]];

Anyone any idea what I am doing wrong?

  • 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-28T04:18:11+00:00Added an answer on May 28, 2026 at 4:18 am
    NSString *string = @"ü";
    const char *c = [string cStringUsingEncoding:NSISOLatin1StringEncoding];
    NSString *newString = [[NSString alloc]initWithCString:c encoding:NSUTF8StringEncoding];
    NSLog(@"%@",newString); // ü
    

    “Malformed UTF-8 sequence” means a sequence of bytes which are invalid in UTF-8. Your problem is unexpected results after parsing a string with a different encoding than the one used by the original author of the string.

    Hexadecimal data C3 BC parsed with UTF-8 encoding is character ü. Instead you used Latin-1 encoding, which results in ü. Then you created a NSString from the Latin-1 parsed string, which means you converted the Latin-1 string to a UTF-16 string (which is the native format of NSString).

    Representing a given data in different encodings shows up as different chars, but doesn’t change the data. Converting to a different encoding does change the data in an attempt to reproduce the same characters. Example: The character ü is C3 83 C2 BC in UTF-8, but C3 BC in Latin-1. So I converted to the same chars in Latin-1 to get the original data, and then I parsed as UTF-8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Objective C and iPhone development. I am using CoreData on
I'm new to Objective-C and I'd like to abstract my database access using a
I 'm new to programming with objective C. I try to read the argb
Still new to Objective C, and I'm having some trouble that I just can't
I'm new with Objective-C, so there probably is a simple solution to this. I
I'm new to Objective-C and iPhone development, and I'm trying to store floating-point values
I'm new to objective-c and would like to know the best practice for importing
I'm new to objective C and I just wanted to get a general clarification
I'm new to Objective-C and Cocoa. I've read that NSInteger and NSNumber are preferred
I'm relatively new to Objective-C and really don't know much about it yet, so

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.