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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:12:38+00:00 2026-05-13T06:12:38+00:00

I have an NSstring that is encoded with UTF8. I want to decode it.

  • 0

I have an NSstring that is encoded with UTF8. I want to decode it.

I tried this but it doesn’t work:

NSString *decodedString = [NSString stringWithUTF8String:[encodedString cStringUsingEncoding:[NSString defaultCStringEncoding]]];

How can I do that?

Thanks

  • 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-13T06:12:38+00:00Added an answer on May 13, 2026 at 6:12 am

    Sending cStringUsingEncoding: to encodedString can only work if encodedString is an NSString object. Having an NSString object is the point you’re trying to get to. Moreover, that method does not decode the string, it encodes the string using the encoding you ask for; thus, in the code you show, you ask for the (already-encoded) string to be encoded in some random encoding (the default C string encoding), then attempt to decode the result as UTF-8. That won’t work.

    You don’t specify what type you’re using for encodedString. Either way, you need to create the NSString object by passing encodedString and its encoding.

    • If encodedString is an NSData object, use the initWithData:encoding: method.
    • If it’s a null-terminated C string; use the initWithCString:encoding: method or (only when it’s UTF-8) the initWithUTF8String: method.
    • If it’s just plain (unterminated) bytes, use the initWithBytes:length:encoding: method.

    All of these except initWithUTF8String: require you to specify the encoding (initWithUTF8String: does by definition), and all of them except initWithData:encoding: come in an autoreleasing convenience version (+stringWith… instead of -initWith…).

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

Sidebar

Related Questions

I have a NSString that is a date and time in this code: YYYY-MM-DD
I have an NSString that then sets a UILabel. This contains unicode such as...
I have an NSString that holds something like this: 4434332124 How can I make
i have an NSString that is value in plist format. i download this string
I have an NSString that I'd like to append a { at the beginning
I have a NSString that will be passed as a parameter to my library's
I have a localized NSString that is something like You win. It was Chuck
I have a piece of NSString that will read Test & Test or with
I have a simple function that returns an NSString after decoding it. I use
I have some code that is supposed to return an NSString. Instead it is

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.