Solved

stringWithUTF8String returns empty string for a non-empty one

Posted on 2012-03-24
2
996 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
2 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS for Mobile Device/iPad 13 122
can't find the executable in Simulator 1 91
iPhone excel activation issues 11 92
sms in cloud 7 33
When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
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…

803 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