티스토리 뷰
아이폰은 한글이 3바이트 라서..
NSInteger convertedLength = [targetStr lengthOfBytesUsingEncoding:(0x80000000 + 0x0422)]; //EUC-KR 식으로 길이 계산
char *converted = [targetStr cStringUsingEncoding:(0x80000000 + 0x0422)]; //EUC-KR 형식으로 인코딩된 char*
NSLog(@"%d 글자 입력", convertedLength);
if (convertedLength > 40) { // 한글은 2바이트로 계산한 Byte 길이 체크
NSData *data = [NSData dataWithBytes:target length:40]; // 딱 거기까지 잘라오기
NSString *convertedStr = [[NSString alloc] initWithData:data encoding:(0x80000000 + 0x0422)]; // 다시 변환 ㅠㅠ
targetStr = convertedStr; //변환된거 저장
[convertedStr release];
}
더 좋은 방법이 있을텐데..............
NSInteger convertedLength = [targetStr lengthOfBytesUsingEncoding:(0x80000000 + 0x0422)]; //EUC-KR 식으로 길이 계산
char *converted = [targetStr cStringUsingEncoding:(0x80000000 + 0x0422)]; //EUC-KR 형식으로 인코딩된 char*
NSLog(@"%d 글자 입력", convertedLength);
if (convertedLength > 40) { // 한글은 2바이트로 계산한 Byte 길이 체크
NSData *data = [NSData dataWithBytes:target length:40]; // 딱 거기까지 잘라오기
NSString *convertedStr = [[NSString alloc] initWithData:data encoding:(0x80000000 + 0x0422)]; // 다시 변환 ㅠㅠ
targetStr = convertedStr; //변환된거 저장
[convertedStr release];
}
더 좋은 방법이 있을텐데..............
'나름 프로그래밍? > Objective-C' 카테고리의 다른 글
파일 존재 여부 검사 (0) | 2012.05.09 |
---|---|
UIWebView 다 불러온 페이지 소스 가져오기 (0) | 2011.09.29 |
UIToolBar 투명하게 만들기 (0) | 2011.06.29 |
통화(금액) 형식 지정 (0) | 2011.06.29 |
UIWebView 컨텐츠 크기 알아오기 (0) | 2011.06.16 |