Java by API/java.text/BreakIterator — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 14:44, 31 мая 2010

BreakIterator.DONE

 
/*
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);
  }
}





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);
  }
}





BreakIterator: getCharacterInstance(Locale locale)

 
import java.text.BreakIterator;
import java.util.Locale;
public class Main {
  public static void main(String[] argv) throws Exception {
    BreakIterator iterator = BreakIterator.getCharacterInstance(Locale.CANADA);
    iterator.setText("aString");
    for (int index = iterator.first(); index != BreakIterator.DONE; index = iterator.next()) {
      System.out.println(index);
    }
  }
}





BreakIterator: getLineInstance(Locale locale)

 

import java.text.BreakIterator;
import java.util.Locale;
public class Main {
  public static void main(String[] argv) throws Exception {
    BreakIterator iterator = BreakIterator.getLineInstance(Locale.CANADA);
    iterator.setText("line1\nline2");
    for (int index = iterator.first(); index != BreakIterator.DONE; index = iterator.next()) {
      System.out.println(index);
    }
  }
}





BreakIterator: getSentenceInstance(Locale locale)

 
import java.text.BreakIterator;
import java.util.Locale;
public class Main {
  public static void main(String[] argv) throws Exception {
    BreakIterator iterator = BreakIterator.getSentenceInstance(Locale.CANADA);
    iterator.setText("this is a test.");
    for (int index = iterator.first(); index != BreakIterator.DONE; index = iterator.next()) {
      System.out.println(index);
    }
  }
}





BreakIterator: getWordInstance(Locale locale)

 

import java.text.BreakIterator;
import java.util.Locale;
public class Main {
  public static void main(String[] argv) throws Exception {
    BreakIterator iterator = BreakIterator.getWordInstance(Locale.CANADA);
    iterator.setText("a sentence");
    for (int index = iterator.first(); index != BreakIterator.DONE; index = iterator.next()) {
      System.out.println(index);
    }
  }
}





BreakIterator: setText(String newText)

 
import java.text.BreakIterator;
import java.util.Locale;
public class Main {
  public static void main(String[] argv) throws Exception {
    BreakIterator iterator = BreakIterator.getWordInstance(Locale.CANADA);
    iterator.setText("a sentence");
    for (int index = iterator.first(); index != BreakIterator.DONE; index = iterator.next()) {
      System.out.println(index);
    }
  }
}