replace for loop with string split method to put string into array