stringReplace()

ストリング内のパターンの出現を、別のパターンに置換します。

構文

public static String stringReplace(String src, String oldpattern,
       String newPattern)
 

パラメーター

src
変更されるストリング。

oldPattern
埋め込みに使用される文字。

newPattern
置換に使用されるストリング・パターン。

戻り値

新しいパターンを含む新しいストリング。

注記

メソッドは、oldPattern で指定された値をすべて、newPattern で指定された値に置換します。単一文字の置換の場合は、Java String クラスで replace() を使用します。oldPattern が見つからない場合は、元の (変更前の) ストリングが戻されます。

次のストリングは、youoyou and dad になります。

stringReplace("momomom and dad", "mom", "you");
 

Copyright IBM Corp. 2004