これは何?

プログラム

使い方

package com.snail;

public class StrReplacerDriver {

  public static String[][] replaceEntry = new String[][] { { "もえ", "萌え" },
      { "もえるごみ", "燃えるゴミ" } ,{"もえぷろ","燃えろプロ野球"}
  };

  public static String source = "もえるごみははげしくもえだした。";

  /**
   * @param args
   */
  public static void main(String[] args) {

    // 最長一致、木構造変換
    RootNode root = new RootNode();

    for (String[] entry : replaceEntry) {
      root.addEntry(entry[0], entry[1]);
    }

    System.out.println("【木構造・最長一致置換】");
    root.dumpTree();

    System.out.println("----");
    System.out.println("置換前:"+source);
    System.out.println("置換後:"+root.replace(source));

    System.out.println("-------------------------");


    // 単純変換
    System.out.println("【単純置換】");
    String simpleReplaced = new String(source);
    for (String[] entry : replaceEntry) {
      System.out.println(entry[0]+"→"+entry[1]);
      simpleReplaced = simpleReplaced.replaceAll(entry[0], entry[1]);
    }
    System.out.println("----");
    System.out.println("置換前:"+source);
    System.out.println("置換後:"+simpleReplaced);

  }
}

Java#JavaSE


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2008-08-14 (木) 01:31:32 (5727d)
Short-URL: https://at-sushi.com:443/pukiwiki/index.php?cmd=s&k=2fed96bd14
ISBN10
ISBN13
9784061426061