iphone - NSString stringWithCharacters Unicode Problem -
this has got simple -- surely method supposed work -- i'm having kind two-byte-to-one-byte problem, think.
the purpose of code generate string of 0 characters of length (10 minus number of digits tacked onto end). looks this:
const unichar 0 = 0x0030; nsstring *zerobuffer = [nsstring stringwithcharacters:&zero length:(10 - [[nsstring stringwithformat:@"%i", photoid] length])];
alternate second line (casting thing @ address &zero):
nsstring *zerobuffer = [nsstring stringwithcharacters:(unichar *)&zero length:(10 - [[nsstring stringwithformat:@"%i", photoid] length])];
0x0030 address of numeral 0 in basic latin portion of unicode table.
if photoid 123 i'd want zerobuffer @"0000000". ends 0 , crazy unicode characters along lines of (not sure how show) this:
0䪨 燱ܾ뿿﹔
i'm assuming i've got data crossing character boundaries or something. i've temporarily rewritten dumb substring thing, seems more efficient.
what doing wrong?
stringwithcharacters:length:
expects first argument address of buffer containing each of characters inserted in string in sequence. it's reading character 0 first character, advancing following memory address , reading whatever data there next character, , on. not right method doing you're trying do.
alas, there isn't built-in repeat-this-string method. see answers here suggestions.
alternatively, can avoid issue , this:
[nsstring stringwithformat:@"%010i", photoid];
that causes number formatter output decimal number padded ten zeroes.
Comments
Post a Comment