Example usage for java.lang String indexOf

List of usage examples for java.lang String indexOf

Introduction

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

Prototype

public int indexOf(String str) 

Source Link

Document

Returns the index within this string of the first occurrence of the specified substring.

Usage

From source file:Main.java

public static String replaceBackslashesWithSlashes(String repBS) {
    if (repBS != null) {
        int ind = -1;
        while ((ind = repBS.indexOf("\\")) != -1) {
            repBS = repBS.substring(0, ind) + "/" + repBS.substring(ind + 1);
        }/* w  w  w. j  a  v  a 2  s  .  c  o  m*/
    }
    return repBS;
}

From source file:Main.java

static public String getValue(String text) {
    String value = "";
    int idx_s = text.indexOf(">");
    int idx_e = text.indexOf("</");
    if (idx_e > idx_s) {
        value = text.substring(idx_s + 1, idx_e);
    }//from   w  ww. j a v  a  2s. co  m
    return cleanValue(value);
}

From source file:Main.java

/** 
 * convert a string with a decimal and a unit such as "5.5 knots"
 * to -> " . 5 knots 5 . " //from  w ww  .j  a va2 s .co  m
 * **/
public static String decimal2Sequence(String value, String unit) {
    if (value.contains(".")) {
        int PointIndex = value.indexOf(".");
        String intVal = value.substring(0, PointIndex);
        String decimal = value.substring(PointIndex + 1, PointIndex + 2);
        value = " . " + intVal + " " + unit + " " + decimal + " . ";
    }
    return value;
}

From source file:Main.java

public static String getDateTomorrow(String date) {

    Date tempDate = null;/*www .j  a  v a2  s  .com*/
    if (date.indexOf("/") > 0)
        tempDate = getDateObj(date, "[/]");
    if (date.indexOf("-") > 0)
        tempDate = getDateObj(date, "[-]");
    tempDate = getDateAdd(tempDate, 1);
    return getFormatDateTime(tempDate, "yyyy/MM/dd");
}

From source file:Main.java

public static String processMoneyFieldByNull(String value) {
    if (value == null) {
        return null;
    }//  w  ww  .  j a va2  s.c  om
    if (value.indexOf(":") > 0) {
        String[] strs = value.split(":");
        if (strs.length > 1 && "null".equals(strs[1])) {
            return strs[0] + ":-";
        }
    }
    return value;
}

From source file:Main.java

static public String quotByEntity(String str) {
    if (str.indexOf('&') != -1) {
        int len = str.length();
        StringBuffer sb = new StringBuffer(len + 4 * 10);
        int offset = 0;
        int pos;/*from ww  w.  j a  va 2s  . c o m*/

        //   while( (pos=str.indexOf('<',offset)) != -1 && offset < len )
        do {
            if ((pos = str.indexOf('&', offset)) == -1) {
                sb.append(str.substring(offset));
                break;
            }

            sb.append(str.substring(offset, pos));
            sb.append("&amp;");
            offset = pos + 1;
        } while (offset < len);

        str = sb.toString();
    }

    if (str.indexOf('<') != -1) {
        int len = str.length();
        StringBuffer sb = new StringBuffer(len + 3 * 10);
        int offset = 0;
        int pos;

        //   while( (pos=str.indexOf('<',offset)) != -1 && offset < len )
        do {
            if ((pos = str.indexOf('<', offset)) == -1) {
                sb.append(str.substring(offset));
                break;
            }

            sb.append(str.substring(offset, pos));
            sb.append("&lt;");
            offset = pos + 1;
        } while (offset < len);

        str = sb.toString();
    }

    return str;
}

From source file:Main.java

/**
 * @brief      get mimitype from one content type string
 * /*from w ww  .j  ava2 s .c  o m*/
 * @param      contentType   [IN]  content type value in html file
 * 
 * @return     Return mimi type value
 */
public static String getMimiType(String contentType) {
    if (contentType != null) {
        int semicolonIndex = contentType.indexOf(';');
        if (semicolonIndex != -1) {
            return contentType.substring(0, semicolonIndex);
        }
    }
    return "text/html";
}

From source file:net.paulgray.bbrest.security.CourseFilter.java

private static String getCourseIdFromUrl(String url) {
    Integer beginCourseIndex = url.indexOf(COURSE_BEGIN_IDENTIFIER) + COURSE_BEGIN_IDENTIFIER.length();
    Integer endCourseIndex = url.indexOf(COURSE_END_IDENTIFIER, beginCourseIndex);
    String id = url.substring(beginCourseIndex, endCourseIndex);
    Logger.getLogger(CourseFilter.class.getName()).log(Level.INFO, "got id: " + id + " from url: " + url);
    return id;//from w w w.  jav  a  2 s.c  om
}

From source file:nanshen.utils.EncryptUtils.java

/**
 * ???/*from www.  jav a  2 s .c  om*/
 * <p />
 * <b>?</b>?{@link #encodePassword(String, String)}?
 *
 * @param encPass 
 * @param rawPass ?
 * @return
 */
public static boolean isPasswordValid(String encPass, String rawPass) {
    int index = encPass.indexOf(PASSWORD_SEPARATOR);
    if (index < 0) {
        return false;
    }
    String salt = encPass.substring(index + 1);
    return encPass.equals(encodePassword(rawPass, salt));
}

From source file:Main.java

public static final boolean validEmailAddress(String address) {
    // need to do better than this
    return (address.indexOf("@") != -1);
}