var a:Character = " " var b:Character = " " var ct = 0 for c in s { if a=="P" && b=="O" && c=="E" { ct += 1 } a = b b = c } return ct Normally, to negate, you just put a minus sign to the left of the thing you want to negate. y = -x sets to the negation of x y = x - 2*x y = 0 - x tf2!.text = String (ct)