QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

spaces-to-tabs

Converts spaces into tabs

  • string
  • tab
  • space
  • conversion

Code

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

Usage

System.out.println(convertSpacesToTab("hello    world", 4)); // Output: hello\tworld