I'm writing a binary/decimal/hexadecimal converter for Android and am trying to format a String in Java with a regex that will add a space to every four characters from right to left.
This code works from left to right, but I am wondering if there is a way I can reverse it.
stringNum = stringNum.replaceAll("....", "$0 ");
Maybe instead of regex use
StringBuilder like this
String data = "abcdefghij"; StringBuilder sb = new StringBuilder(data); for (int i = sb.length() - 4; i > 0; i -= 4) sb.insert(i, ' '); data = sb.toString(); System.out.println(data);
ab cdef ghij