Repeat characters in a string
问题 I know this is a simple problem, but for some reason it wont click. I want to repeat characters in a string for a fixed amount. For example: str = 'abcde' temp = '' x = 8 for i in 0..x if str[i].nil? temp << '' else temp << str[i] end end Except I get no input. What I need is: abcdeabc Please, any help would be appreciated. If there is a better working way to do this instead of my not working naive approach, I would like to know 回答1: Using ljust should do it: str = 'abcde' str.ljust(8, str) #