Looks a bit ugly, copying to alloca, altering to truncate, altering back..
I think would look more readable if you used a StringBuffer and built up leading scope to add to array as you go.