Re: [問題] char to NSString

看板MacDev作者 (Traveler)時間13年前 (2012/03/31 01:48), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《zonble (zonble)》之銘言: : ※ 引述《heyshi (baw)》之銘言: : : NSData *buf; : : NSString *str; : : 想請問有沒有更短的寫法?? : : 我改寫成以下寫法就爆了 Q_Q : : str = [NSString stringWithFormat:@"%d", : : [[buf subdataWithRange:NSMakeRange(127, 1)] bytes]]; : 試試看這樣 : str = [NSString stringWithFormat:@"%d", : *(char *)[[buf subdataWithRange:NSMakeRange(127, 1)] bytes]]; 我是覺得 程式寫成這樣很不直覺 @@ 我會這樣寫 Byte *p = (Byte *)[buf bytes]; NSString *str = [NSString stringWithFormat:@"%d",p[127]]; 如果怕值 out of bound 取一下[buf length]就好了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.49.142
文章代碼(AID): #1FTV7q0P (MacDev)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
文章代碼(AID): #1FTV7q0P (MacDev)