As someone else already hinted, you would probably benefit from reading perlretut and pos.
It may seem like overkill for this problem but learning regular expressions will make string processing problems like this a lot easier. And almost all serious programming languages today have a regular expression library very much like perl's, so chances are high you'd be able to use that knowledge if you're using some other language too.
| [reply] |
Oh, backreferences were the catch then? I saw about it in the tutorial... Thank you guys, both of you!
| [reply] |
I only used a backreference so that I could have the single character in $1. You can do this without them, but then you'd have to substr to get a single char from the range to print.
| [reply] |
OK, Joost's code works, now it's time for you to go to work.
The code uses only a regex and two built-in functions, pos and length, and string concatenation (the . operator). Time to apply Your Mother's suggestions about documentation access and do some reading. Then, maybe try some variations and see what happens. After that, specific questions will usually elicit pertinent answers. | [reply] [d/l] [select] |