It's not necessary to scan the string. You can simply ask for a range to be returned from a string. So, the entire body of your method could be:
name[0,n]