def findnth(s, substr, n):
    """find the nth occurance of substr in s
    
    return the offset"""
    offset = -1
    for i in range(n):
        offset = s.find(substr, offset+1)
        if offset == -1: break
    return offset