List of usage examples for java.lang String indexOf
public int indexOf(String str)
From source file:Main.java
public static void main(String[] args) { String xmlFileName = "data.xml"; String xPath = "//article/body/p"; Document document = getDocument(xmlFileName); List<Node> nodes = document.selectNodes(xPath); for (Node node : nodes) { String nodeXml = node.asXML(); System.out.println("Left >> " + nodeXml.substring(3, nodeXml.indexOf("<ref")).trim()); System.out.println(// ww w . j av a 2 s .c om "Right >> " + nodeXml.substring(nodeXml.indexOf("</ref>") + 6, nodeXml.length() - 4).trim()); } }
From source file:com.joliciel.jochre.yiddish.JochreYiddish.java
public static void main(String[] args) throws Exception { Map<String, String> argMap = new HashMap<String, String>(); for (String arg : args) { int equalsPos = arg.indexOf('='); String argName = arg.substring(0, equalsPos); String argValue = arg.substring(equalsPos + 1); argMap.put(argName, argValue);//from w w w.j av a2 s.c om } JochreYiddish jochre = new JochreYiddish(); jochre.execute(argMap); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);// w w w .java2 s . com factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getDocumentElement(); Text text1 = (Text) element.getFirstChild(); String string = text1.getData(); String word = "some"; Text text2 = text1.splitText(string.indexOf(word)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/* w w w. j a v a2 s .c o m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getDocumentElement(); Text text1 = (Text) element.getFirstChild(); String string = text1.getData(); String word = "some"; Text text2 = text1.splitText(string.indexOf(word)); Element newElement = doc.createElement("b"); newElement.appendChild(text2); }
From source file:MainClass.java
public static void main(String args[]) { String s = "public static void main(String args[]) {"; System.out.println(s);/* w ww. ja v a2 s . c o m*/ System.out.println("indexOf(t) = " + s.indexOf('t')); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/* w w w .j a v a 2 s.co m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getDocumentElement(); Text text1 = (Text) element.getFirstChild(); String string = text1.getData(); String word = "some"; Text text2 = text1.splitText(string.indexOf(word)); Element newElement = doc.createElement("b"); newElement.appendChild(text2); element.insertBefore(newElement, text2); }
From source file:MainClass.java
public static void main(String args[]) { String s = "public static void main(String args[]) {"; System.out.println(s);//from w ww . j av a2s.c o m System.out.println("indexOf(the) = " + s.indexOf("pub")); }
From source file:org.eclipse.swt.snippets.Snippet327.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 327"); shell.setLayout(new FillLayout()); final Browser browser; try {//from w w w . j a va 2 s. c o m browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } browser.setText(createPage(0)); browser.addLocationListener(LocationListener.changingAdapter(event -> { String location = event.location; int index = location.indexOf(PREAMBLE); if (index != -1) { int pageNumber = Integer.valueOf(location.substring(index + PREAMBLE.length())).intValue(); browser.setText(createPage(pageNumber)); event.doit = false; } })); shell.setBounds(10, 10, 200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ComputeResult.java
public static void main(String[] args) { String original = "software"; StringBuilder result = new StringBuilder("hi"); int index = original.indexOf('a'); /*1*/ result.setCharAt(0, original.charAt(0)); /*2*/ result.setCharAt(1, original.charAt(original.length() - 1)); /*3*/ result.insert(1, original.charAt(4)); /*4*/ result.append(original.substring(1, 4)); /*5*/ result.insert(3, (original.substring(index, index + 2) + " ")); System.out.println(result);/*from ww w. ja v a 2 s . co m*/ }
From source file:Snippet80.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); for (int i = 0; i < 2; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("item " + i); for (int j = 0; j < 2; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText("item " + j); for (int k = 0; k < 2; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText("item " + k); }// www .j a v a 2 s . c om } } tree.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TreeItem[] selection = tree.getSelection(); TreeItem[] revisedSelection = new TreeItem[0]; for (int i = 0; i < selection.length; i++) { String text = selection[i].getText(); if (text.indexOf("1") > 0) { TreeItem[] newSelection = new TreeItem[revisedSelection.length + 1]; System.arraycopy(revisedSelection, 0, newSelection, 0, revisedSelection.length); newSelection[revisedSelection.length] = selection[i]; revisedSelection = newSelection; } } tree.setSelection(revisedSelection); } }); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }