implement some string methods in python to avoid alloc issues