BreakIterator: first() : BreakIterator « java.text « Java by API






BreakIterator: first()

 
/*
Character Boundaries: 0 3 6 
Word Boundaries:0 6 
*/
import java.text.BreakIterator;
import java.util.Locale;

public class HangulTextBoundaryDetection {
  static void printBoundaries(String source, BreakIterator bi) {
    bi.setText(source);
    int boundary = bi.first();

    while (boundary != BreakIterator.DONE) {
      System.out.print(boundary + " ");
      boundary = bi.next();
    }
  }

  public static void main(String s[]) {
    String hangul = "\u1112\u1161\u11ab\u1100\u1173\u11af";
    BreakIterator ci = BreakIterator.getCharacterInstance(Locale.KOREAN);
    BreakIterator wi = BreakIterator.getWordInstance(Locale.KOREAN);

    System.out.print("Character Boundaries: ");
    printBoundaries(hangul, ci);
    System.out.print("\nWord Boundaries:");
    printBoundaries(hangul, wi);
  }
}

           
         
  








Related examples in the same category

1.BreakIterator.DONE
2.BreakIterator: getCharacterInstance(Locale locale)
3.BreakIterator: getLineInstance(Locale locale)
4.BreakIterator: getSentenceInstance(Locale locale)
5.BreakIterator: getWordInstance(Locale locale)
6.BreakIterator: setText(String newText)