// returns true if second is a substring of first
method contains(first:String, second:String)->Boolean is public{
    var iter1 := first.iter
    var iter2 := second.iter
    var current1 := iter1.next
    var current2 := iter2.next
    var soFar := false
    while {iter1.havemore} do {
        if(current1 == current2) then{
            if(!iter2.havemore) then {return true}
            else{
                soFar := true
                current1 := iter1.next
                current2 := iter2.next
            }
        }
        else{
            soFar := false
            current1 := iter1.next
            iter2 := second.iter
            current2 := iter2.next
        }
    }
    if((current1 != current2) || iter2.havemore) then {soFar := false}
    return soFar
}

method caseInsensitiveEqual(first:String, second:String)->Boolean is public{
    var iter1 := first.iter
    var iter2 := second.iter
    var c1:Number := 0
    var c2:Number := 0
    var soFar := true
    if(first.length != second.length) then {return false}
    while {iter1.havemore && soFar} do {
        c1 := iter1.next.ord
        c2 := iter2.next.ord
        if((65 <= c1) && (c1 <= 90)) then {
            soFar := (c1 == c2) || ((c1 + 32) == c2)
        }
        else{ if((65 <= c2) && (c2 <= 90)) then {
                  soFar := (c1 == (c2 + 32))
              }
              else{soFar := (c1 == c2)}
        }
        if(!soFar) then {return false}      
    }
    return soFar
}

// returns string with all non-letter characters removed
method removeNonLetters(s:String) is public{
    var changed := s
    var iter := s.iter
    var c := ""
    var n := 0
    while{iter.havemore} do {
        c := iter.next
        n := c.ord
        if((n < 65) || ((n > 90) && (n < 97)) || (n > 122)) then {
            changed := changed.replace(c)with("")
        }
    }
    return changed
}


// converts string to lower case, going letter by letter

method toLower(s:String) is public{
    var aLIST := ["A","B","C","D","E","F","G","H","I","J","K","L","M",
        "N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
    var alist := ["a","b","c","d","e","f","g","h","i","j","k","l","m",
        "n","o","p","q","r","s","t","u","v","w","x","y","z"]
 
    for(1..26) do{i->
        s := s.replace(aLIST.at(i))with(alist.at(i))
    }
    return s
}