Counting the occurences of a substring

Text, array, dict, file, are virtual classes, and each instance may use methods of the virtual class, as find here, method of text.

class String

int count(text base, text sea) `one of the methods of the String class
  int ctr = 0
  int i = 0
  while forever
    i = base.find(sea, i)   ` return the position, if found
    if i = nil break        ` else, return nil (not in list).
    i + 1      ` advancing the pointer inside the base text
    ctr + 1   ` counter of occurences
  /while
return ctr

/class

String str           `declaring an instance of the String class
print str.count("somestring", "string")