Solved

stringWithUTF8String returns empty string for a non-empty one

Posted on 2012-03-24
2
1,009 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 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run an android app on IOS 3 78
itunes-not recognising iphone 4 54
Wordpress navigation menus do not show up 14 52
Exchange 2010 - SBS 2011 - Public calenders 4 28
The release of the iPhone 6 and the iPhone 6 Plus was extremely successful for Apple. However when iOS 8.1 was introduced, many iPhone users complained of quick battery drainage. Without even knowing, you may be unnecessarily using up your battery p…
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…

732 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