NSString creating problem when contains chinese font
NSString creating problem when contains chinese font
- Subject: NSString creating problem when contains chinese font
- From: Calvin Hou <email@hidden>
- Date: Wed, 01 Oct 2003 11:23:02 -0400
Hi All,
I got a problem when I create an NSString. The program is trying to read a
string from a file, then modify some words, then display it in a NSTextView
window. The string contains simple-chinese and ascii.
If I don't do any modification of the string, everything is fine. Both
simple-chines and ascii are shown in the NSTextview as expected.
The problem is, if I modified one or some chinese word, the creation of the
NSString always return a NULL. But it's ok when I changed some ascii.
The piece of code is shown as following,
//Get string from a file. This string contains chinese GB and ascii.
char *contents = (char *)malloc(100);
[[fhdict_file readDataOfLength:100] getBytes: contents];
//Modify one chinese character, if don't changed, everything is fine.
contents[55] = 0xB8; contents[56] = 0x71;
// Create NSString temp which will be displayed in NSTextView
NSString * temp = [[NSString alloc] initWithUTF8String: contents];
I was wondering if anybody met the same problem? And how to solve it? It
seems that if using unicode instead of UTF-8 to create the string, the
modification of the string is ok. But I don't want to do some extra work to
convert GB-code into unicode.
Thanks a lot.
Calvin
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.