String output = "I\\AM\\So\\Cool"; while (true) { int pos = output.indexof("\\"); // check to see if its not in there // eg: work has finished if (pos == -1) break; output = output.substring(pos+1) + " " + output.substring(0, pos); }