本文整理匯總了Java中org.apache.commons.lang3.StringUtils.indexOf方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.indexOf方法的具體用法?Java StringUtils.indexOf怎麽用?Java StringUtils.indexOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.indexOf方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extractUsername
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
/**
* Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because
* the DN is in an unrecognized format, the entire DN is returned.
*
* @param dn the dn to extract the username from
* @return the exatracted username
*/
public static String extractUsername(String dn) {
String username = dn;
// ensure the dn is specified
if (StringUtils.isNotBlank(dn)) {
// determine the separate
final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ",";
// attempt to locate the cd
final String cnPattern = "cn=";
final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern);
if (cnIndex >= 0) {
int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex);
if (separatorIndex > 0) {
username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex);
} else {
username = StringUtils.substring(dn, cnIndex + cnPattern.length());
}
}
}
return username;
}
示例2: buildURL
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
private GrpcURL buildURL(ConsulService service) {
try {
for (String tag : service.getTags()) {
if (StringUtils.indexOf(tag, Constants.PROVIDERS_CATEGORY) != -1) {
String toUrlPath = StringUtils.substringAfter(tag, Constants.PROVIDERS_CATEGORY);
GrpcURL salukiUrl = GrpcURL.valueOf(GrpcURL.decode(toUrlPath));
return salukiUrl;
}
}
} catch (Exception e) {
log.error("convert consul service to url fail! service:" + service, e);
}
return null;
}
示例3: rmXSSDangerousCharacters
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
private String rmXSSDangerousCharacters(String script, String[] xss) {// 移除存在XSS攻擊威脅的字符串
if (null == xss || xss.length == 0) {
return script;
}
for (String remove : xss) {
if (StringUtils.isBlank(remove)) {
continue;
}
if (StringUtils.indexOf(script, remove) < 0) {
continue;
}
if (remove.length() == 1) {
script = StringUtils.remove(script, remove.charAt(0));
log.warn('[' + remove + "]已移除");
continue;
}
Pattern p = Pattern.compile(remove, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(script);
while (m.find()) {
String st = m.group();
script = StringUtils.remove(script, remove);
log.warn('[' + st + "]已移除");
}
}
return script;
}
示例4: normalizePath
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
/**
* 在Windows環境裏,兼容Windows上的路徑分割符,將 '/' 轉回 '\'
*/
public static String normalizePath(String path) {
if (Platforms.FILE_PATH_SEPARATOR_CHAR == Platforms.WINDOWS_FILE_PATH_SEPARATOR_CHAR
&& StringUtils.indexOf(path, Platforms.LINUX_FILE_PATH_SEPARATOR_CHAR) != -1) {
return StringUtils.replaceChars(path, Platforms.LINUX_FILE_PATH_SEPARATOR_CHAR,
Platforms.WINDOWS_FILE_PATH_SEPARATOR_CHAR);
}
return path;
}
示例5: getSubstring
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
private String getSubstring(String start, String end) {
int first = StringUtils.indexOf(logicRepresentation, start);
int second = StringUtils.indexOf(logicRepresentation, end);
return StringUtils.substring(logicRepresentation, first + 1, second);
}
示例6: handleIndex
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
@Override
protected int handleIndex(CharSequence str, CharSequence searchStr, int startPos) {
return StringUtils.indexOf(str, searchStr, startPos);
}
示例7: toCsvString
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
/**
* Parse fields as csv string,
*/
public static String toCsvString(Object... elements) {
StringBuilder line = new StringBuilder();
int last = elements.length - 1;
for (int i = 0; i < elements.length; i++) {
if (elements[i] == null) {
if (i != last) {
line.append(FIELD_SEPARATOR);
}
continue;
}
String field = elements[i].toString();
// check for special cases
int ndx = field.indexOf(FIELD_SEPARATOR);
if (ndx == -1) {
ndx = field.indexOf(FIELD_QUOTE);
}
if (ndx == -1 && (field.startsWith(SPACE) || field.endsWith(SPACE))) {
ndx = 1;
}
if (ndx == -1) {
ndx = StringUtils.indexOf(field, SPECIAL_CHARS);
}
// add field
if (ndx != -1) {
line.append(FIELD_QUOTE);
}
field = StringUtils.replace(field, QUOTE, DOUBLE_QUOTE);
line.append(field);
if (ndx != -1) {
line.append(FIELD_QUOTE);
}
// last
if (i != last) {
line.append(FIELD_SEPARATOR);
}
}
return line.toString();
}