code: public static String stripNonAlphaNumericCharacters(String input) {
      StringBuilder output = new StringBuilder();
      for (int i = 0; i < input.length(); i++) {
        char current = input.charAt(i);
        if ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ".indexOf(current) >= 0)
          output.append(current);
      }
      return output.toString();
    }
docs: Strips all non A-Z/0-9 characters from the input string. Spaces are left intact.