Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
 
Class Notes

Monday November 6 , 2000
 
String Processing  

 
  Class Notes  -- Monday November 6 , 2000

   
   CSC212 - November 6, 2000
   ======================================
  
   Lecture Topic: STRING PROCESSING
  
   Specification: (very partial) of java.lang.string class
    
   1) <String>.length() -> int
      
       "cs1 exams are fun!".length()
        returns 18
  
   2) <String>.indexOf(<String>) -> <int>
  
        012345678911234
       "frim fram sauce".indexOf("fr")  
        returns 0
  
        012345678911234
       "frim fram sauce".indexOf("fra")  
        returns 5
       
        strings, like arrays are indexed from the left
  
   3a) <String>.substring(<int>) -> <String>
  
        Returns the substring from the position specified 
        by the parameter to the end of the string.  
  
         012345678911234
        "monday".substring(3)
         returns "day"
     
   3b) <String>.substring(<int>,<int>) -> <String>
  
        Returns the substring from the position of the 
        first parameter to the position one less than 
        the second parameter.
  
         012345678911234
        "tired hand".substring (2,7)
                                | |__ Does not Print
         returns "red h"        |____ First Letter Printed
  
  
     LAB - "STRING THING"
      
    A) Enter your name "Directory Style" 
  
         012345678910
         Byron, Bahr
  
    B) length of names - singer.length()
  
    C) singer.substring(10)
  
         0123456789112345
        "Holliday, Billie"
  
    D) substring
  
    E) singer.indexOf(",")
      
         "Holliday, Billie"
  
    F1) Remove commands //
        First Name = Operator style method
                     Returns value
  
    F2) First Name Operator method definition
  
        static private String firstName(String, dsname)
                                 |        |       |
                         method__|        |       |
                                          |       |
                                   type___|       |
                                                  |
                           directory style name___|
         {
           compute position of comma
           compute first name
           return first name
         }
           introduce variable
           bind variable
  
    More String Functionality
  
     #  "cat" == "dog"
               |_________only works for numbers
  
    4) <String>.equals (<String>) -> <boolean>
  
        "cat".equals("dog") -> False
        "cat".equals("cat") -> True
        "cat".equals("Cat") -> False
  
    5) <String>.equalsIgnoreCase(<String>)
  
    6) <String>.compareTo (<String>) -> <int>
  
       returns: 
         0 - if the two strings are equal
         something negative - 
            if the receiving string is alphebetically
            less than the parameter.
         something positive - 
            if the receiving string is alphebetically
            greater than the parameter.
  
     Ex:  "cat".compareTo("bat")
            |               |____parameter
            |__Receiving String
  
            returns something Positive
  
          "bat".compareTo("bats")
  
            returns something Negative
  
  
   =========================================================
   123456789112345678921234567893123456789412345678951234567