1 /* 2 * Program to illustrate some basic character string processing functionality. 3 * Created by: Hunter Gersitz 10 October, 2019 Suny Oswego 4 * */ 5 6 package stringthing; 7 8 public class StringOps { 9 10 public static void main(String[] args) { 11 12 // ESTABLISH SOME STRINGS 13 String date = "Thursday, October 10, 2019"; 14 String time = "8:34 AM"; 15 String lab = "String Thing"; 16 17 // COMPUTE THE LENGTHS OF THE STRINGS 18 int dateLength = date.length(); 19 int timeLength = time.length(); 20 int labLength = lab.length(); 21 System.out.println("\ndateLength = " + dateLength); 22 System.out.println("timeLength = " + timeLength); 23 System.out.println("labLength = " + labLength); 24 25 // COMPUTE POSITIONS 26 int p1 = date.indexOf(", "); 27 int p2 = time.indexOf(" "); 28 int p3 = lab.indexOf("ing"); 29 System.out.println("\np1 = " + p1); 30 System.out.println("p2 = " + p2); 31 System.out.println("p3 = " + p3); 32 33 // COMPUTE SOME 2 ARGUMENTS SUBSTRING VALUES 34 System.out.println("\ndate.substring(0,9) = " + date.substring(0,9)); 35 System.out.println("time.substring(2,4) = " + time.substring(2,4)); 36 System.out.println("lab.substring(7,8) = " + lab.substring(7,8)); 37 38 // COMPUTE SOME 1 ARGUMENTS SUBSTRING VALUES 39 System.out.println("\ndate.substring(10) = " + date.substring(10)); 40 System.out.println("time.substring(0) = " + time.substring(0)); 41 System.out.println("lab.substring(7) = " + lab.substring(7)); 42 43 // CREATE A STRING 44 String line = date + " | " + time + " | " + lab; 45 System.out.println("\nline = " + line); 46 47 } 48 } 49