List of usage examples for java.lang String indexOf
public int indexOf(String str)
From source file:ToStringDemo.java
public static void main(String[] args) { double d = 858.48; String s = Double.toString(d); int dot = s.indexOf('.'); System.out.println(dot + " digits before decimal point."); System.out.println((s.length() - dot - 1) + " digits after decimal point."); }
From source file:SubStringDemo.java
/** * @author suraj.gupta/*from ww w.jav a 2 s . c o m*/ */ public static void main(String[] args) { String s = "suraj.gupta@yahoo.com"; // email id in a String int IndexOf = s.indexOf("@"); // returns an integer which tells the position of this substring "@" in the parent String "suraj.gupta@yahoo.com" String domainName = s.substring(IndexOf); //prints the String after that index System.out.println("Taking Domain name from an email id " + domainName); }
From source file:MainClass.java
public static void main(String[] Args) { String filepath = "C:/myFile.txt"; File aFile = new File(filepath); FileOutputStream outputFile = null; if (aFile.isFile()) { File newFile = aFile;/*from w w w. j a v a 2 s. com*/ do { String name = newFile.getName(); int period = name.indexOf('.'); newFile = new File(newFile.getParent(), name.substring(0, period) + "_old" + name.substring(period)); } while (newFile.exists()); aFile.renameTo(newFile); } try { outputFile = new FileOutputStream(aFile); System.out.println("myFile.txt output stream created"); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String encoding = "ISO-8859-1"; URL u = new URL("http://www.java2s.com"); URLConnection uc = u.openConnection(); String contentType = uc.getContentType(); int encodingStart = contentType.indexOf("charset="); if (encodingStart != -1) { encoding = contentType.substring(encodingStart + 8); }/*from w w w . j av a 2 s . c o m*/ InputStream in = new BufferedInputStream(uc.getInputStream()); Reader r = new InputStreamReader(in, encoding); int c; while ((c = r.read()) != -1) { System.out.print((char) c); } }
From source file:Main.java
public static void main(String[] args) { String haystack = "this is a test"; String needle1 = "Java"; int index1 = haystack.indexOf(needle1); if (index1 != -1) System.out.println("The string contains the substring " + needle1); else/*from ww w .ja v a 2 s. co m*/ System.out.println("The string does not contain the substring " + needle1); }
From source file:MainClass.java
public static void main(String args[]) { String letters = "abcdefghijklmabcdefghijklm"; System.out.printf("\"def\" is located at index %d\n", letters.indexOf("def")); System.out.printf("\"def\" is located at index %d\n", letters.indexOf("def", 7)); System.out.printf("\"hello\" is located at index %d\n\n", letters.indexOf("hello")); }
From source file:MainClass.java
public static void main(String args[]) { String letters = "abcdefghijklmabcdefghijklm"; System.out.printf("'c' is located at index %d\n", letters.indexOf('c')); System.out.printf("'a' is located at index %d\n", letters.indexOf('a', 1)); System.out.printf("'$' is located at index %d\n\n", letters.indexOf('$')); }
From source file:com.hp.test.framework.Reporting.TestPath.java
public static void main(String ar[]) throws IOException { URL location = Test.class.getProtectionDomain().getCodeSource().getLocation(); String path = location.toString(); path = path.substring(6, path.indexOf("lib")); String Logos_path = path + "ATU Reports/HTML_Design_Files/IMG"; String Source_logs_path = path + "HTML_Design_Files/IMG"; String Source_Framework_Logo_path = Source_logs_path + "/Framework_Logo.jpg"; String Source_hp_logo_path = Source_logs_path + "/hp.png"; String Source_reports_path = Source_logs_path + "/reports.jpg"; File Target_dir = new File(Logos_path); File Source = new File(Source_Framework_Logo_path); FileUtils.copyFileToDirectory(Source, Target_dir); File Source_Reports = new File(Source_reports_path); FileUtils.copyFileToDirectory(Source_Reports, Target_dir); File Source_hp = new File(Source_hp_logo_path); FileUtils.copyFileToDirectory(Source_hp, Target_dir); }
From source file:Main.java
public static void main(String args[]) { String s = "this is a test from java2s.com."; System.out.println(s);/* ww w .j a v a2 s .com*/ System.out.println("indexOf(t) = " + s.indexOf('t')); }
From source file:Main.java
public static void main(String args[]) { String s = "this is a test from java2s.com."; System.out.println(s);// ww w. j a v a 2 s.c om System.out.println("indexOf(the) = " + s.indexOf("the")); }