Java String to Long convertStringToLong(String string)

Here you can find the source of convertStringToLong(String string)

Description

Converts a string into a long value.

License

Open Source License

Parameter

Parameter Description
string The string to convert.

Declaration

public static long convertStringToLong(String string) 

Method Source Code

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

public class Main {
    /**/*from www  .j  a  va  2 s.  co  m*/
     * Converts a string into a long value. This is used for the player appearance updating to
     * update a players username.
     * 
     * @param string The string to convert.
     */
    public static long convertStringToLong(String string) {
        long l = 0L;
        int i = 0;
        do {
            char c = string.charAt(i);
            l *= 37L;
            if ((c >= 'A') && (c <= 'Z')) {
                l += '\001' + c - 65;
            } else if ((c >= 'a') && (c <= 'z')) {
                l += '\001' + c - 97;
            } else if ((c >= '0') && (c <= '9')) {
                l += '\033' + c - 48;
            }
            i++;
            if (i >= string.length()) {
                break;
            }
        } while (i < 12);
        while ((l % 37L == 0L) && (l != 0L)) {
            l /= 37L;
        }
        return l;
    }
}

Related

  1. asLong(String value)
  2. atol(final String str, final long def)
  3. atol(String pString_)
  4. atol(String s)
  5. atol(String str)