Java Tab Expand expandTabs(String inputString, int numberOfSpaces)

Here you can find the source of expandTabs(String inputString, int numberOfSpaces)

Description

expand Tabs

License

Open Source License

Declaration

public static String expandTabs(String inputString, int numberOfSpaces) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String expandTabs(String inputString, int numberOfSpaces) {
        if (inputString.indexOf('\t') == -1)
            return inputString;
        int inputStringLength = inputString.length();
        StringBuffer buffer = new StringBuffer(inputStringLength);
        String spaces = nCopies(numberOfSpaces, ' ');
        for (int i = 0; i < inputStringLength; i++) {
            char c = inputString.charAt(i);
            if (c == '\t')
                buffer.append(spaces);/*  w w w. j av  a 2 s.com*/
            else
                buffer.append(c);
        }

        return buffer.toString();
    }

    public static String nCopies(int copyCount, char charToCopy) {
        StringBuffer buffer = new StringBuffer(copyCount);
        for (int i = 0; i < copyCount; i++)
            buffer.append(charToCopy);

        return buffer.toString();
    }
}

Related

  1. expandTabs(int ntabs)
  2. expandTabs(String s, int tabSize)
  3. expandTabs(String str)
  4. expandTabs(String string, int tabSize)
  5. expandTabs(String text, int tabSize)