Java Tab Expand expandTabs(String text, int tabSize)

Here you can find the source of expandTabs(String text, int tabSize)

Description

expand Tabs

License

Open Source License

Declaration

public static String expandTabs(String text, int tabSize) 

Method Source Code

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

public class Main {
    public static String expandTabs(String text, int tabSize) {
        String rv = "";
        if (text != null) {
            if (text.indexOf('\t') >= 0) {
                StringBuilder buf = new StringBuilder();
                int len = text.length();
                for (int i = 0; i < len; i++) {
                    char ch = text.charAt(i);
                    if (ch == '\t') {
                        int n = tabSize - (buf.length() % tabSize);
                        for (int k = 0; k < n; k++) {
                            buf.append((char) '\u0020');
                        }/*from  ww w  .  j av a2  s. co m*/
                    } else {
                        buf.append(ch);
                    }
                }
                rv = buf.toString();
            } else {
                rv = text;
            }
        }
        return rv;
    }
}

Related

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