Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
Created September 28, 2014 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanNutt/cef101ed3f82db40613e to your computer and use it in GitHub Desktop.
Save RyanNutt/cef101ed3f82db40613e to your computer and use it in GitHub Desktop.
I needed an easy way to rotate a string a set number of places for a lab I was setting up. This returns s rotated by distance spots and loops back around.
private String rotateString(String s, int distance) {
String out = "";
for (int i=0; i<s.length(); i++) {
out += s.charAt((i + distance) % s.length());
}
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment