HOME | Overview | Syllabus | Instructor | Lectures | Laboratories | Readings | Assignments | Resources | Other Links
CS 1713 Lecture 17: Strings
October 8, 1999
Strings are mentioned in the text in Section 3.4 (page 94) and section 5.2 (pages 188-189). The String class is summarized in Appendix C (pages 716-719).

The String class.

  • Comparison of Strings:
  • String methods:

  • Example: Determine whether thisChar is a vowel.
         String vowels = new String("aeiouAEIOU"); 
         if (vowels.indexOf(thisChar) != -1)
            System.out.println("This character is a vowel");
    

  • Example: Find the position of the first vowel in myString. (Do not use a loop.) Hint: convert to lowercase and then do brute force. A more elegant solution is to use recursion.

  • Example: Design a TextLine class which holds a string and supports insertion and deletion.
    public class TextLine {
       private String theLine;
    
       //constructor
       public TextLine (String line) {
          theLine = new String(line);
       } 
    
       //accessor methods
    
    
       //modifier methods 
       public void Insert(String phrase, int position) {
    
       }
    
       public void Delete(String phrase) {
    
       }
         
       public void Replace(String oldphrase, String newphrase) {
    
       }
    
    }
    

    Objective: Acquire a basic understanding of strings
    Last revision: December 13, 1999 at 1:30 pm