Hi all! I would like to know how to format a string to a pattern in Java. The input String is looking like "xxxxxx" and the formated String must look like "xxxxx x" with a space between the last 2 characters. How can this is done?
@ all Thanks for the input on this problem . Can this code be adapted for the following My input string is: 1A4567 the output string must be 7 1A456. Of course I would need a function which would convert back the string since the user inputs the desired looking string and actually I search in the database for the 2nd.
// From input to output public static String toOutput(String input) { return new StringBuffer(input.charAt(5)+" ").append(input.substring(0,5)).toString(); }
// The reverse way public static String toInput(String output) { return new StringBuffer(output.substring(2)).append(output.charAt(0)).toString(); }