string contains function, memory allocation