# N00b question

**URL:** <https://www.ruby-forum.com/t/n00b-question/138022>\
**Category:** Ruby\
**Created:** [May 19, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/n00b-question/138022 "2008-05-19T16:36:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mileschatterji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mileschatterji](https://www.ruby-forum.com/u/mileschatterji)\
**Post date:** [May 19, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/n00b-question/138022/1 "2008-05-19T16:36:36Z")

</div>

somewhat new to ruby, and im trying to write a simple program to print  
 ![]()  
and I would like the program to list the next one as  
 ![](http://www.empiremotoring.org/pictures/pp.5.17.08/IMG_0989.jpg)  
 ![](http://www.empiremotoring.org/pictures/pp.5.17.08/IMG_0990.jpg)

and so on, this is what I have so far, I am just having trouble getting  
it add +1 to the end ever time because it dosent like numbers in the  
string, I have tried several things but non of which worked out. Any  
advice would be a great help here is the code

# Img forum tag lister

puts "What is your url: " # url from input  
url = gets.chomp

puts "What is your files name: " # file name from input (IMG\_ for canon  
DSC\_ for sony etc.)  
file = gets.chomp

puts "How many files: " # # of files wanted to print from input  
num = gets.to\_i

puts "beginning file #: " # beginning number extension, ( number at end  
of picture file eg IMG\_0987, would be 0987)

bnum = gets.chomp

print (" ![]()") \*num.to\_i #  
prints IMG tag.

I realize that you can put the numbers into a sting without first  
converting but the how would you go about having it add +1 after it has  
been converted?

Thanks, --Miles

---

<div class="post-metadata">

**Author:** ![mileschatterji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mileschatterji](https://www.ruby-forum.com/u/mileschatterji)\
**Post date:** [May 19, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/n00b-question/138022/2 "2008-05-19T17:09:21Z")

</div>

Hi,

Miles C. wrote:

> somewhat new to ruby, and im trying to write a simple program to print  
> ![]()  
> and I would like the program to list the next one as  
> ![](http://www.empiremotoring.org/pictures/pp.5.17.08/IMG_0989.jpg)  
> ![](http://www.empiremotoring.org/pictures/pp.5.17.08/IMG_0990.jpg)
> 
> and so on, this is what I have so far, I am just having trouble getting  
> it add +1 to the end ever time because it dosent like numbers in the  
> string, I have tried several things but non of which worked out. Any  
> advice would be a great help here is the code
> 
> # Img forum tag lister
> 
> puts "What is your url: " # url from input  
> url = gets.chomp
> 
> puts "What is your files name: " # file name from input (IMG\_ for canon  
> DSC\_ for sony etc.)  
> file = gets.chomp
> 
> puts "How many files: " # # of files wanted to print from input  
> num = gets.to\_i
> 
> puts "beginning file #: " # beginning number extension, ( number at end  
> of picture file eg IMG\_0987, would be 0987)
> 
> bnum = gets.chomp
> 
> print (" ![]()") \*num.to\_i  
> try this:

num.times { puts “ ![]()” }

> I realize that you can put the numbers into a sting without first  
> converting but the how would you go about having it add +1 after it has  
> been converted?
> 
> Thanks, --Miles

Regards,  
Park H.

---

<div class="post-metadata">

**Author:** ![mileschatterji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mileschatterji](https://www.ruby-forum.com/u/mileschatterji)\
**Post date:** [May 19, 2008, 5:13pm UTC](https://www.ruby-forum.com/t/n00b-question/138022/3 "2008-05-19T17:13:55Z")

</div>

Excellent, Thanks a lot.

---

<div class="post-metadata">

**Author:** ![mileschatterji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mileschatterji](https://www.ruby-forum.com/u/mileschatterji)\
**Post date:** [May 19, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/n00b-question/138022/4 "2008-05-19T17:16:26Z")

</div>

-------- Original-Nachricht --------

> Datum: Mon, 19 May 2008 23:36:36 +0900  
> Von: Miles C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: n00b question

> it add +1 to the end ever time because it dosent like numbers in the  
> puts "What is your files name: " # file name from input (IMG\_ for canon
> 
> print (“ ![]()”) \*num.to\_i #  
> prints IMG tag.
> 
> I realize that you can put the numbers into a sting without first  
> converting but the how would you go about having it add +1 after it has  
> been converted?

Hi Miles,

you can use the pound sign :

res=‘5’  
p “The answer is #{res=res.succ}”  
p res

res=5  
p “The answer is #{res=res.succ}”  
p res

… but, be careful for “negative number-strings” …

Best regards,

Axel

to evaluate

---

<div class="post-metadata">

**Author:** ![mileschatterji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mileschatterji](https://www.ruby-forum.com/u/mileschatterji)\
**Post date:** [May 19, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/n00b-question/138022/5 "2008-05-19T17:45:23Z")

</div>

Thanks for the help and the quick replys, that helped out a lot and  
learned something new.

---

<div class="post-metadata">

**Author:** ![mileschatterji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mileschatterji](https://www.ruby-forum.com/u/mileschatterji)\
**Post date:** [May 20, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/n00b-question/138022/6 "2008-05-20T15:27:15Z")

</div>

Or you could use a regexp on the string to separate out the number, then  
increment it, and put the string back together again.

But this is a Ruby N.y here, fresh from Perl and still finding out how  
to do things the proper Ruby way. 😉
