Fixed string parsing function to handle empty string case