Solved

stringWithUTF8String returns empty string for a non-empty one

Posted on 2012-03-24
2
985 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

     Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON (https://github.com/SwiftyJSON/SwiftyJSON). If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now