Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sandeepac

macrumors newbie
Original poster
Jul 10, 2008
3
0
Cochin
Sir

I have a problem with encoding of strings

strcpy(myCString, [MyNSString cStringUsingEncoding:NSUnicodeStringEncoding ]);

CFStringRef str1 = CFStringCreateWithCString(NULL,myCString,kCFStringEncodingUnicode);
NSLog((NSString*)str1);

if my unicode string is मनज मानमान मानमा.
then i am getting Only मनज as output.
can you please help me to solve this problem.


Thanking you

Sandeep
 

Enuratique

macrumors 6502
Apr 28, 2008
276
0
Sir

I have a problem with encoding of strings

strcpy(myCString, [MyNSString cStringUsingEncoding:NSUnicodeStringEncoding ]);

CFStringRef str1 = CFStringCreateWithCString(NULL,myCString,kCFStringEncodingUnicode);
NSLog((NSString*)str1);

if my unicode string is मनज मानमान मानमा.
then i am getting Only मनज as output.
can you please help me to solve this problem.


Thanking you

Sandeep

Try changing your logging code to

Code:
NSLog(@"%@", str1);

and see if you get the expected string back.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
strcpy(myCString, [MyNSString cStringUsingEncoding:NSUnicodeStringEncoding ]);

CFStringRef str1 = CFStringCreateWithCString(NULL,myCString,kCFStringEncodingUnicode);

That cannot possibly work. C strings are for strings using 8 bit characters. NSUnicodeStringEncoding uses the 16 bit Unicode encoding. As soon as you have a character with a Unicode value from 0 to 255, strcpy () sees a zero byte and thinks that is the end of the string. Same if you have a character with a Unicode value like 256, 512, 768 and so on.

You need to use the appropriate UTF8 encodings. UTF8 encodes Unicode in eight bit values in a way that is compatible with C string functions.

In this case, the whole conversion is not needed anyway. Go to http://www.developer.com and look for "toll free bridging". Might save you lots of work and code and memory and execution time and problems when you mix Cocoa and Core Foundation.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.