Completed the string function according to the flow chart.