
UConverter::setSubstChars 함수는 특정 문자를 대체 문자로 설정하는 함수입니다. 예를 들어, 한글 '가'를 '가'로 대체하는 것을 말합니다.
대체 문자를 설정하면 모든 문자에 대체가 적용되지 않습니다. 대체 문자를 설정한 문자만 대체가 적용됩니다.
예시 코드는 다음과 같습니다.
#hostingforum.kr
cpp
#include
#include
int main() {
// 대체 문자를 설정할 문자열
UChar32 src[] = { 0x3131, 0x3134 }; // '가'
UChar32 dst[] = { 0x3131, 0x3134 }; // '가'
// 대체 문자를 설정할 UConverter 객체
UConverter* converter = ucnv_open("UTF-8");
UConverter* substConverter = ucnv_open("UTF-8");
// 대체 문자를 설정
ucnv_setSubstChars(substConverter, src, dst, 1);
// 대체 문자를 설정한 문자열을 출력
UChar32* output = new UChar32[2];
ucnv_fromUChars(substConverter, output, 2, src, 2);
printf("%04x %04xn", output[0], output[1]);
delete[] output;
// 대체 문자를 설정하지 않은 문자열을 출력
ucnv_fromUChars(converter, output, 2, src, 2);
printf("%04x %04xn", output[0], output[1]);
delete[] output;
// 객체를 닫습니다.
ucnv_close(converter);
ucnv_close(substConverter);
return 0;
}
이 예시 코드에서, '가'를 '가'로 대체하는 것을 설정하고, 대체 문자를 설정한 문자열을 출력하는 것을 볼 수 있습니다.
2025-04-14 06:20