You can step through each character in your string easily enough (String.toCharArray()) and build up your replacement String (using a StringBuilder, StringBuffer, new array of chars - whatever you like). If you ignore the hyphens you just need to chuck in a hyphen every five characters in your new string. If the strings are variable length you may have to do a little arithmetic up front to find out where this hyphen should be. A Map will hold your mapped key/value pair - just swap the old value with the value in the Map and append it to the new String.
Joined: Dec 09, 2006
Thanks again for your input... Could you elaborate a bit more of what you mean with some sample code?