๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’š ๊ฐœ๋ฐœ/iOS

[iOS] Objective-C NSString -> char* ๊ณผ char* -> NSString

by devshin.kr 2021. 10. 21.
728x90
// char* -> NSString
char szText[] = "hello World";
NSString* nsStr = [NSString stringWithUTF8String: szText];


// NSString -> char*
NSString* nsStr = @"hello World";
char* strTmp = (char*)[nsStr UTF8String];


// NSString -> unsigend char*
NSString* nsStr = @"hello World";
unsigned char* strTmp = (unsigned char*)[nsStr UTF8String];


// NSString ๊ธธ์ด ๊ตฌํ•˜๊ธฐ
NSString* nsStr2 = @"check length!";
int nLength = [nsStr2 length];

 

 

23๋…„ 5์›” 11์ผ ์ถ”๊ฐ€

NSString ์€ ์ธ์ฝ”๋”ฉ์„ ์„ ํƒํ•ด์•ผ ํ•˜๋ฉฐ, ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋กœ๋ถ€ํ„ฐ ๋””์ฝ”๋”ฉ์ด ์‹คํŒจํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•˜์—ฌ ์˜ต์…”๋„ ํƒ€์ž…์„ ๋ฆฌํ„ดํ•œ๋‹ค.

 

๋Œ“๊ธ€