Need help with string variable formatting

No i think it’s not right idea.
Maybe algorithm with loop will be much better for this work.