QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

tabs-to-spaces

Converts tabs into spaces

  • string
  • tab
  • space
  • conversion

Code

public static String convertTabToSpace(String text, int spacesPerTab) {
    return text.replaceAll("\t", " ".repeat(spacesPerTab));
}

Usage

System.out.println(convertTabToSpace("hello\tworld", 2)); // "hello  world"