
IntlBreakIterator 클래스의 getPartsIterator 메서드는 텍스트를 분할한 후, 분할된 텍스트를 Iterator 형태로 반환하는 메서드입니다.
IntlBreakIterator를 사용하여 텍스트를 분할한 후, 분할된 텍스트를 Iterator로 반환하는 방법은 다음과 같습니다.
1. IntlBreakIterator 객체를 생성하여 텍스트를 분할합니다.
2. getPartsIterator 메서드를 호출하여 분할된 텍스트를 Iterator로 반환합니다.
3. Iterator를 통하여 분할된 텍스트를 순회합니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
cpp
#include
#include
int main() {
// 텍스트를 분할할 문자열
const char* text = "Hello, World!";
// IntlBreakIterator 객체를 생성
UErrorCode status = U_ZERO_ERROR;
UBreakIterator* breakIterator = ubrk_open(U_FINE, text, -1, &status);
// getPartsIterator 메서드를 호출하여 분할된 텍스트를 Iterator로 반환
UBreakIterator* partsIterator = ubrk_getPartsIterator(breakIterator, &status);
// Iterator를 통하여 분할된 텍스트를 순회
int32_t count = ubrk_count(partsIterator);
for (int32_t i = 0; i < count; i++) {
UChar32 c = ubrk_next(partsIterator);
printf("%c", c);
}
// 자원 해제
ubrk_close(partsIterator);
ubrk_close(breakIterator);
return 0;
}
이 예제에서는 IntlBreakIterator를 사용하여 텍스트를 분할하고, 분할된 텍스트를 Iterator로 반환하여 순회하는 방법을 보여줍니다.
2025-03-08 12:11