Java String Length Get lengthOfStartingWhitespace(String s)

Here you can find the source of lengthOfStartingWhitespace(String s)

Description

length Of Starting Whitespace

License

Open Source License

Return

the length of the starting whitespace for the line, or the string length if it is all whitespace

Declaration

public static int lengthOfStartingWhitespace(String s) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**//from w w  w .  jav a 2 s  .  co m
     * @return the length of the starting whitespace for the line, or the string
     * length if it is all whitespace
     */
    public static int lengthOfStartingWhitespace(String s) {
        int n = s.length();
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            // TODO: This currently only deals with ASCII whitespace.
            // Read until a non-space
            if (c != ' ' && c != '\t') {
                return i;
            }
        }

        return n;
    }
}

Related

  1. lengthIfAllAlpha(String str)
  2. lengthIntegers(String str)
  3. lengthMinusColors(String thisStr)
  4. lengthMinusTrailingWhitespace(String line)
  5. lengthOfCommonPrefix(String s1, String s2)
  6. lengthOfString(final String cadena)
  7. lengthTokensField(String fieldName)
  8. lengthToString(double value, boolean proportional)
  9. lengthUCP(String s)