Java String Length Get lengthExpandedTabs(String string, int toIdx, int tabWidth)

Here you can find the source of lengthExpandedTabs(String string, int toIdx, int tabWidth)

Description

Returns the length of a String prefix with tabs expanded.

License

Open Source License

Parameter

Parameter Description
string the input String
toIdx index in string (exclusive) where the calculation stops
tabWidth the distance between tab stop position.

Return

the length of string.substring(0, toIdx) with tabs expanded.

Declaration

public static int lengthExpandedTabs(String string, int toIdx, int tabWidth) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

public class Main {
    /**//from  w w  w .  ja v  a 2s .  c  o  m
     * Returns the length of a String prefix with tabs expanded.
     * Each tab is counted as the number of characters is takes to
     * jump to the next tab stop.
     * @param string the input String
     * @param toIdx index in string (exclusive) where the calculation stops
     * @param tabWidth the distance between tab stop position.
     * @return the length of string.substring(0, toIdx) with tabs expanded.
     */
    public static int lengthExpandedTabs(String string, int toIdx, int tabWidth) {
        int len = 0;
        for (int idx = 0; idx < toIdx; idx++) {
            if (string.charAt(idx) == '\t') {
                len = (len / tabWidth + 1) * tabWidth;
            } else {
                len++;
            }
        }
        return len;
    }
}

Related

  1. lengthBetween(String param, int minLength, int maxLength)
  2. lengthByteInPrepared(String s)
  3. lengthCheck(final String str, final int minLength, final int maxLength)
  4. lengthConstToString(int val, int len)
  5. LengthConversionFactor(String OldUnits)
  6. lengthExpression(final String operand, final long length)
  7. lengthField(String propertyName)
  8. lengthFormat(String str, int maxLength)
  9. lengthIfAllAlpha(String str)