いくつかのif条件をチェックし、次のようにいくつかの置換操作を実行する必要がある文字列があります。
for(int i =0; i<10;i++){
if(name[i].contains("sometext")){
name[i] = name[i].replaceAll("someregexpattern","replacementtexthere");
}
}
'if'条件を使用して毎回'sometext'の存在をチェックする代わりに、次のように簡単に言うことができますか?
for(int i =0; i<10;i++){
name[i] = name[i].replaceAll("someregexpattern","replacementtexthere");
}
とにかく、文字列'name'に'regexpattern'の意味が含まれていない場合、それは何も置き換えません。したがって、if条件はパフォーマンスの観点から重要です。
前もって感謝します。