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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:30:58+00:00 2026-05-20T22:30:58+00:00

Hi I use the following to convert std::string to NSString but it return (null)

  • 0

Hi
I use the following to convert std::string to NSString but it return (null) while trying to display the value of the nsstring

I need it to return instead of (null) empty at conversion time any suggestion

StudyDate=[NSString stringWithCString:studyDate length:strlen(studyDate)]; 

any suggestion to avoid null values

best regards

  • 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-20T22:30:59+00:00Added an answer on May 20, 2026 at 10:30 pm

    Edit: The syntax @"string" is used only for constructing NSString. With std::string you should use the standard "string" syntax.

    NSString* aConstantNSString = @"foo";
    const char* aConstantCString = "foo";
    std::string aConstantStdString = "foo";
    CFStringRef aConstantCFString = CFSTR("foo");
    

    1. +stringWithCString:length: has been deprecated since the very early beginning of the iPhone SDK. If the string contains only ASCII characters, often you could use +stringWithUTF8String: instead.

    2. Your method works only when studyDate is a C string (i.e. const char*), but you said you have a std::string. There is no method to directly convert a std::string into an NSString. You must use .c_str() to create the C string first:

      StudyDate = [NSString stringWithUTF8String:studyDate.c_str()];
      

      (But the above shouldn’t be the cause you’re getting (null) because passing a std::string to +stringWithCString:length: or even strlen should give a compile-time error immediately.

      'error: cannot convert ‘std::string’ to ‘const char*’ in argument passing'
      

      So studyDate should already be a const char*. We need more context (code) to see what’s going on.)

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

Sidebar

Related Questions

To convert from a system::String to an std::string, I use the following code: IntPtr
I have the following std::string '2010-08-10T23:59:00' and I need to convert it to a
I'm trying to convert wstring to string with use of locale facets but I
I have the following function void AddNodeValue(XMLNode& node, std::string& value); I want to use
I'm trying to use strtotime to convert the following date: 07/09/2009 17:01:27 It's the
I'm trying to write a simple function to convert a std::function<> object while binding
I am trying to use the following code to convert a hash of options
How come when I use the following method, to be used to convert all
Each time I use Merge() I have the following: 'Cannot implicitly convert type 'void'
Following this question , I use this function to convert arrays to objects, function

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.