public static String tabsToSpaces ( String in , int tabSize ) { StringBuilder buf = new StringBuilder ( ) ; int width = 0 ; for ( int i = 0 ; i < in . length ( ) ; i ++ ) { switch ( in . charAt ( i ) ) { case ' ' : int count = tabSize - ( width % tabSize ) ; width += count ; while ( -- count >= 0 ) { buf . append ( ' ' ) ; } break ; case ' ' : width = 0 ; buf . append ( in . charAt ( i ) ) ; break ; default : width ++ ; buf . append ( in . charAt ( i ) ) ; break ; } } return buf . toString ( ) ; }
Converts tabs to consecutive spaces in the specified string .