to.tetramorph.util
クラス StringReplacer

java.lang.Object
  上位を拡張 to.tetramorph.util.StringReplacer

public class StringReplacer
extends Object

文字列置換ツール。 staticメソッドで文字列置換を行うものと、オブジェクトを作成して連続置換を 行う方法と二種類用意している。


コンストラクタの概要
StringReplacer(String text)
          オブジェクトを作成する。
 
メソッドの概要
 void replace(String target, String replacement)
          このオブジェクトが持つ文字列中からtarget文字列を探し、それをreplacementに 置換する。
 void replace(String target, StringBuilder replacement)
          このオブジェクトが持つ文字列中からtarget文字列を探し、それをreplacementに 置換する。
static String replace(String text, String target, String replacement)
          文字列を置換する。
 String toString()
          このオブジェクトが持つ文字列を返す。
 
クラス java.lang.Object から継承されたメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

コンストラクタの詳細

StringReplacer

public StringReplacer(String text)
オブジェクトを作成する。連続置換を行うときに使用する。

パラメータ:
text - 置換をほどこす文字列
メソッドの詳細

replace

public void replace(String target,
                    String replacement)
このオブジェクトが持つ文字列中からtarget文字列を探し、それをreplacementに 置換する。

パラメータ:
target - 置換のターゲットとなる文字列
replacement -

replace

public void replace(String target,
                    StringBuilder replacement)
このオブジェクトが持つ文字列中からtarget文字列を探し、それをreplacementに 置換する。

パラメータ:
target - 置換のターゲットとなる文字列
replacement -

toString

public String toString()
このオブジェクトが持つ文字列を返す。(置換後の文字列を返す)

オーバーライド:
クラス Object 内の toString

replace

public static String replace(String text,
                             String target,
                             String replacement)
文字列を置換する。text中のtargetすべてをreplacementに置換する。 String#replaceAll()は、正規表現による置き換えだが、正規表現ゆえに特定の 文字が入っていると置換に失敗することがおきる。このメソッドはごく単純な 置換なので、そのような問題が生じることがない。StringBuilderを使っている ので比較的高速。すくなくとも正規表現の置換よりはずっと速い。