[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

n00b question

Miles Chatterji

5/19/2008 2:37:00 PM

somewhat new to ruby, and im trying to write a simple program to print
[IMG] tags for php forums on my screen so I dont have to copy and paste
100 of them and change the pictures number every time. Example I have
127 pictures from a race that I would like to post, the tag is
[img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
and I would like the program to list the next one as
[img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
[img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]

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 ("[img]" + url + file + bnum.to_s +=1 + ".jpg [/img]") *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
--
Posted via http://www.ruby-....

5 Answers

Heesob Park

5/19/2008 3:09:00 PM

0

Hi,

Miles Chatterji wrote:
> somewhat new to ruby, and im trying to write a simple program to print
> [IMG] tags for php forums on my screen so I dont have to copy and paste
> 100 of them and change the pictures number every time. Example I have
> 127 pictures from a race that I would like to post, the tag is
> [img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
> and I would like the program to list the next one as
> [img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
> [img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
>
> 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 ("[img]" + url + file + bnum.to_s +=1 + ".jpg [/img]") *num.to_i
try this:

num.times { puts "[img]#{url}#{file}#{bnum=bnum.succ}.jpg[/img]" }

>
> 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 Heesob
--
Posted via http://www.ruby-....

Miles Chatterji

5/19/2008 3:14:00 PM

0

Excellent, Thanks a lot.

--
Posted via http://www.ruby-....

Axel Etzold

5/19/2008 3:16:00 PM

0


-------- Original-Nachricht --------
> Datum: Mon, 19 May 2008 23:36:36 +0900
> Von: Miles Chatterji <miles@mama.indstate.edu>
> An: ruby-talk@ruby-lang.org
> Betreff: n00b question

> somewhat new to ruby, and im trying to write a simple program to print
> [IMG] tags for php forums on my screen so I dont have to copy and paste
> 100 of them and change the pictures number every time. Example I have
> 127 pictures from a race that I would like to post, the tag is
> [img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
> and I would like the program to list the next one as
> [img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
> [img]http://www.empiremotoring.org/pictures/pp.5.17.08/IM...[/img]
>
> 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 ("[img]" + url + file + bnum.to_s +=1 + ".jpg [/img]") *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


> Thanks, --Miles
> --
> Posted via http://www.ruby-....

--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/mult...

Miles Chatterji

5/19/2008 3:46:00 PM

0

Thanks for the help and the quick replys, that helped out a lot and
learned something new.
--
Posted via http://www.ruby-....

Dave Bass

5/20/2008 1:27:00 PM

0

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 Nooby here, fresh from Perl and still finding out how
to do things the proper Ruby way. ;-)



--
Posted via http://www.ruby-....