Example usage for java.lang String substring

List of usage examples for java.lang String substring

Introduction

In this page you can find the example usage for java.lang String substring.

Prototype

public String substring(int beginIndex, int endIndex) 

Source Link

Document

Returns a string that is a substring of this string.

Usage

From source file:FileUtil.java

public static String StripFileExtension(String fileName) {
    return fileName.substring(0, fileName.lastIndexOf('.'));
}

From source file:Main.java

public static int getNewsId(String link) {
    return Integer.parseInt(link.substring(link.lastIndexOf("/") + 1, link.length()).split("\\.")[0]);
}

From source file:Main.java

public static String formatPhoneNum(String phoneNum) {
    String target = phoneNum.substring(3, 7);
    phoneNum = phoneNum.replace(target, "*****");
    return phoneNum;
}

From source file:Main.java

public static String updateFrist(String fldName) {
    String first = fldName.substring(0, 1).toUpperCase();
    String rest = fldName.substring(1, fldName.length());
    String newStr = new StringBuffer(first).append(rest).toString();
    return newStr;
}

From source file:Main.java

public static String convert128to16UUID(String uuid) {
    return uuid.substring(START_INDEX_UUID, END_INDEX_UUID);
}

From source file:MainClass.java

private static String decrypt(char[] password, String text) throws Exception {
    String salt = text.substring(0, 12);
    String ciphertext = text.substring(12, text.length());
    BASE64Decoder decoder = new BASE64Decoder();
    byte[] saltArray = decoder.decodeBuffer(salt);
    byte[] ciphertextArray = decoder.decodeBuffer(ciphertext);

    PBEKeySpec keySpec = new PBEKeySpec(password);

    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithSHAAndTwofish-CBC");

    SecretKey key = keyFactory.generateSecret(keySpec);

    PBEParameterSpec paramSpec = new PBEParameterSpec(saltArray, 1000);

    Cipher cipher = Cipher.getInstance("PBEWithSHAAndTwofish-CBC");
    cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);

    return new String(cipher.doFinal(ciphertextArray));
}

From source file:Main.java

public static String removeBom(String str) {

    byte[] isBom = str.substring(0, 1).getBytes();
    if (isBom.length == 3 && isBom[0] == (byte) 0xEF && isBom[1] == (byte) 0xBB && isBom[2] == (byte) 0xBF) {
        return str.substring(1);
    }//from   ww w . j ava  2  s . c  om

    return str;
}

From source file:Main.java

static public String stripTopLevelTag(String xmlString) {
    return xmlString.substring(xmlString.indexOf('>') + 1, xmlString.lastIndexOf('<'));
}

From source file:Main.java

/**
 * Returns a file path corresponding to a potential SMAP input
 * for the given compilation input (JSP file).
 *///from  w  w  w .j av  a 2  s .  c  o  m
private static String inputSmapPath(String path) {
    return path.substring(0, path.lastIndexOf('.') + 1) + "smap";
}

From source file:Main.java

/**
 * Compute the parent of a path. Note : path must lead to an element.
 * /*from   w w w  . ja  v a  2s  . c o  m*/
 * @param path the path with at least one slash, eg "./elem".
 * @return the parent of path, eg ".".
 */
public final static String parentOf(String path) {
    return path.substring(0, path.lastIndexOf('/'));
}