Code Red > AutoLISP (Vanilla / Visual)
Write to text file with incrementing text
Dommy2Hotty:
I'm creating a photo gallery of a trip I just got back from on my website. I've been learning HTML recently, and this is what I've come up with:
--- Code: ---<td><a href='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_002.jpg' title='Click to enlarge'>
<img src='http://home.comcast.net/~dominic.cesare/pictures/Louisville/Louisville_002.jpg' width=100 height=75 border=0></a>
<br>002</td>
--- End code ---
Now, all the pictures follow that naming format: Louisville_XXX.jpg
Can LISP write that 51 times, incrementing any instance of the number?
MP:
Yep, but why use lisp?
Dommy2Hotty:
--- Quote from: MP on November 16, 2005, 05:57:16 PM ---Yep, but why use lisp?
--- End quote ---
To further my knowledge of LISP. I don't want to copy, paste, find, replace, repeat...If you have any other suggestions, do share.
MP:
It's just that it's not a cadd app that's all. You could do it in vb, vba, vbscript, python yada ... I just wondered why you chose lisp.
Play with this --
--- Code: ---(defun c:Test ( / rset foo main )
(defun rset ( text padding maxlen )
(substr
( (lambda ( )
(while
(<
(strlen (setq padding (strcat padding padding)))
maxlen
)
)
(setq text (strcat padding text))
)
)
(- (strlen text) (1- maxlen))
)
)
(defun foo ( integer / integerAsPaddedString )
(strcat
"<td>"
"<a href='http://home.comcast.net/~dominic.cesare"
"/pictures/Louisville/Louisville_"
(setq integerAsPaddedString (rset (itoa integer) "000" 3))
".jpg' title='Click to enlarge'>\n"
"<img src='http://home.comcast.net/~dominic.cesare"
"/pictures/Louisville/Louisville_"
integerAsPaddedString
".jpg' width=100 height=75 border=0></a>\n"
"<br>"
integerAsPaddedString
"</td>\n"
)
)
(defun main ( / i )
(setq i 0)
(repeat 51
(princ
(foo
(setq i (1+ i))
)
)
)
(princ)
)
(main)
)
--- End code ---
Obviously you could modify it so it writes to file etc. but I decided to keep it relatively simple.
(Warning, very Q&D).
:)
Dommy2Hotty:
I appreciate it. Like I said, I figured this is something that I could do with LISP, and in doing so, learn about expressions I haven't used before, and how I can apply them in the future. As far as the other program languages: I'm a newb.
Navigation
[0] Message Index
[#] Next page
Go to full version