Java String Truncate truncateInt(String intStr)

Here you can find the source of truncateInt(String intStr)

Description

truncate Int

License

Apache License

Parameter

Parameter Description
intStr a parameter

Declaration

public static int truncateInt(String intStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   ww  w .j a  va  2 s .  c o m
     * 
     * @param intStr
     * @return
     */
    public static int truncateInt(String intStr) {
        int len = intStr.length();

        int result = 0;
        for (int i = 0; i < len; i++) {
            char c = intStr.charAt(i);
            if (c >= '0' && c <= '9') {
                result = result * 10;
                result += c - '0';
            } else {
                break;
            }
        }

        return result;
    }
}

Related

  1. truncateFileType(String p)
  2. truncateFirstEnd(String str)
  3. truncateHashToInt(String hash)
  4. truncateIfTooLong(String string, int maxLength)
  5. truncateIgnoreCase(String aString, String trailingSubString)
  6. truncateJavaBeanMethodName(String methodName, int prefixLength)
  7. truncateLabel(String label)
  8. truncateLeadingSlash(String uri)
  9. truncateLongName(String name, int nameLength)