Lesson 63 - Strings - Part 5 - Programming Logic Part -13 using indexOf () and substring () methods

Опубликовано: 01 Январь 1970
на канале: JavaJourneyWithMadhavi
11
3

In this video, indexOf and lastIndexOf is explained with the help of two programs, one to find the indices of a given character in the text and the second one to find the indices of a given string in the text. The method substring is explained with the help of two programs, one to extract Title from name, and the second to extract filename from a given path.

Link to the Book - Essentials of Computer Applications:
https://www.amazon.in/Essentials-Comp...

Link to Lesson 7 - Escape Sequences:
   • Lesson 7 Java Tokens - Literals, Escape Se...  

Link to Lesson 14 - Input in Java using Scanner class:
   • Lesson 14 - Input in Java using Scanner class  

Link to Lesson 62 - indexOf, lastIndexOf, substring methods:
   • Lesson 62   Strings - Part 4 - indexOf (),...  

Practice Exercise Lesson 63: IndexOf()

String a= “This is my book.”
1. System.out.println(a.indexOf(‘s’)); 2. System.out.println(a.indexOf(‘m’));
3. System.out.println(a.indexOf(‘o’)); 4. System.out.println(a.indexOf(‘p’));
5. System.out.println(a.indexOf(‘t’)) 6. System.out.println(a.indexOf(‘s’,4)); 7. System.out.println(a.indexOf(‘o’,12)); 8. System.out.println(a.indexOf(“book”)); 9. System.out.println(a.indexOf(“is”,5));
lastIndexOf()
String a= “This is my book.”
1. System.out.println(a.lastIndexOf(‘o’)); 2. System.out.println(a.lastIndexOf (‘i’)); 3. System.out.println(a.lastIndexOf (‘t’)); 4. System.out.println(a.lastIndexOf (‘j’));
5. System.out.println(a.lastIndexOf(“my”));
6. System.out.println(a. lastIndexOf (“trees”));
substring()
1. System.out.println(“Mysore Maharaja Palace”.substring(7)); 2. System.out.println(“Mysore Maharaja Palace”.substring(0,6)); 3. System.out.println(“How are you”.substring(4));