List of usage examples for java.lang String indexOf
public int indexOf(String str, int fromIndex)
From source file:Main.java
public static String getAttribute(String attribute, String text, int idx) { int close = text.indexOf(">", idx); int attrIdx = text.indexOf(attribute + "=\"", idx); if (attrIdx == -1) { return null; }/*from w w w . jav a 2s. com*/ if (attrIdx > close) { return null; } int attrStartIdx = attrIdx + attribute.length() + 2; int attrCloseIdx = text.indexOf("\"", attrStartIdx); if (attrCloseIdx > close) { return null; } return unescapeXml(text.substring(attrStartIdx, attrCloseIdx)); }
From source file:Main.java
public static int toPathIndex(String fileName, int fromIndex) { int point = fileName.indexOf('/', fromIndex); if (point == -1) { point = fileName.indexOf('\\', fromIndex); }/*from w w w . ja v a 2s . co m*/ return point; }
From source file:Main.java
/** * Find the string value of an attribute starting at position k in * a text string, returning the string value of the attribute, or * null if the attribute is not present. Note: this method returns * the value of the attribute with normalized whitespace. * @param text the XML string./*from ww w .j a v a 2 s .com*/ * @param k the starting point in the XML string to search for the attribute. * @param attr the name of the attribute. * @return the string value of the attribute, or null if the attribute is not * present. */ public static String getAttribute(String text, int k, String attr) { int kk = text.indexOf(">", k); if (kk < 0) return null; String t = text.substring(k, kk).replaceAll("\\s+", " ").replaceAll(" =", "=").replaceAll("= ", "="); k = t.indexOf(" " + attr + "="); if (k < 0) return null; k = t.indexOf("=", k) + 2; if (t.charAt(k - 1) != '"') return null; kk = t.indexOf("\"", k); if (kk < 0) return null; return t.substring(k, kk); }
From source file:Main.java
private static int getIndexOpeningTag(String tag, String text, int start) { // consider whitespace? int idx = text.indexOf("<" + tag, start); if (idx == -1) { return -1; }/*w w w .ja va 2 s . co m*/ char next = text.charAt(idx + 1 + tag.length()); if ((next == '>') || Character.isWhitespace(next)) { return idx; } else { return getIndexOpeningTag(tag, text, idx + 1); } }
From source file:Main.java
public static void highlight(JTextComponent textComp, String pattern) throws Exception { removeHighlights(textComp);/*from ww w . j a va 2 s . com*/ Highlighter hilite = textComp.getHighlighter(); Document doc = textComp.getDocument(); String text = doc.getText(0, doc.getLength()); int pos = 0; while ((pos = text.indexOf(pattern, pos)) >= 0) { hilite.addHighlight(pos, pos + pattern.length(), myHighlightPainter); pos += pattern.length(); } }
From source file:Main.java
public static int indexOfEnhanced(String src, int fromIndex, String... strs) { for (String s : strs) { if (src.indexOf(s, fromIndex) != -1) return src.indexOf(s); }//ww w . j a v a 2 s .com return -1; }
From source file:Main.java
public static String replaceAndEndnote(String text, String holderString, String replacement, String noteTag, String noteSplit) {/* w w w.java2 s .c om*/ StringBuilder note = new StringBuilder(); note.append(noteTag); String tmp = new String(text); int start = 0; while ((start = tmp.indexOf(holderString, start)) >= 0) { note.append(start + noteSplit); start += holderString.length(); } start = note.length() - noteSplit.length(); if (note.substring(start).equals(noteSplit)) note.delete(start, note.length()); return text.replace(holderString, replacement) + note; }