Performing multiple substring replacements on a string I have code like the following, which performs a series of replacements on a string, to convert it to its final form.

public String convertString(String string) {

String convertedString = string;

if( string.contains("something")) {
    convertedString = convertStringA(string);

    return convertedString;
} else if (string.contains("something else")) {
    convertedString = convertStringB(string);

    return convertedString;
} ...

// many more else if blocks

else if (string.contains("something else")) {
    convertedString = convertStringXXX(string);

    return convertedString;
} ...

}


How can I do it better?
Your Algorithm is a little bit too abstract to provide a one size fits all solution.

What does it mean, when a string contains "something" or "something else"?
Are they completely different strings like "I know (something)" and "He gave me (something else)"? Or are there similarities like:
"Peter knows (something)" and "Joe knows (something else)". So "knows" would be the keyword after which your phrase occurs. "Contains" is somehow a little bit unprecise.

If it is relativly easy to extract the substring you need -perhaps with a regular expression- you could use a HashMap to provide the correct converter with a simple call with the phrase as the key. 

public class Converters {

  HashMap&lt;String, Converter&gt; converters=new HashMap&lt;String, Converter&gt;();    

  public Converters(){
      // Fill Hashmap here
  }

  public Converter getConverterFor(String phrase){
      if (!converters.containsKey(phrase)) throw new NoConverterFoundException();
      return converters(phrase);
  }    

}


Converter is here an interface, which all of your converters have to implement.
This solution provides easy maintenance - a new Converter needs only one new entry in the HashMap. And no unreadable if-else-whattheeckyouwantelse-blocks anymore.

But this is only one possible solution. A better solution requires more information on your phrases.