?
Solved

stringWithUTF8String returns empty string for a non-empty one

Posted on 2012-03-24
2
Medium Priority
?
1,040 Views
Last Modified: 2012-03-28
Hi.

I'm developing an iPhone application which gets some data from SQLite to a mutable array. Inside the loop that treats every record, I have something like this:

char *nameC = (char *)sqlite3_column_text(myStatement, 1);
name = [NSString stringWithUTF8String:(const char*)nameC];

Open in new window


Most of records are converted well, but the problem is for a few records I'm getting nameC correctly but I'm getting an empty string on name variable (not a null pointer, but an empty string). Some of the working strings have some non-english characters, and some of the failing strings have just english characters, so I don't think it's an encoding issue.

Just if it helps, I'm using Automatic Counting References (so I think it couldn't be a memory leak issue) and also

Any clue ?
0
Comment
Question by:gplana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 2000 total points
ID: 37761478
Sounds like you are getting autoreleased between those two statements.
I'm really very new to obj-c, but I would try this:

name = [NSString stringWithUTF8String: strdup(nameC)];

Open in new window

0
 
LVL 15

Author Closing Comment

by:gplana
ID: 37778267
Now it seems to work. Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to take pictures with depth using iOS 10
Email is way too noisy, prone to hiding the important stuff, and really becoming unreliable for critical/timely communications. There are better ways to communicate.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question