Page 1 of 1
find is like Instr, what's like RevInstr?
Posted: Wed Apr 08, 2009 10:40 am
by axtens
G'day everyone
(find) is like VBScript's Instr(). What is the equivalent for VBScript's RevInstr() wherein one searches for the first occurrence from the other end of the string? (find (reverse))?
Kind regards,
Bruce.
Re: find is like Instr, what's like RevInstr?
Posted: Wed Apr 08, 2009 1:10 pm
by axtens
axtens wrote:What is the equivalent for VBScript's RevInstr() wherein one searches for the first occurrence from the other end of the string? (find (reverse))?
I think I'll have a go at answering my own question.
Code: Select all
(set 'reverse-find
(lambda (findThis inThis)
(- (length inThis) (find (reverse findThis) (reverse inThis)) (length findThis))))
and then some demonstrations plus a comparison of what it finds against what (find) finds.
Code: Select all
(set 'toFind "dog")
(set 'sentence "My first dog's fleas are on my second dog's blanket")
(println (slice sentence (reverse-find toFind sentence) (length toFind)))
; "dog"
(println (slice sentence (reverse-find toFind sentence)))
; "dog's blanket"
(println (slice sentence (find toFind sentence)))
; "dog's fleas are on my second dog's blanket"
Am I doing okay so far?
Kind regards,
Bruce.
Posted: Wed Apr 08, 2009 1:18 pm
by Kazimir Majorinc
I don't know VBscript but it looks OK to me.
I think you are progressing quite good. Are you experienced programmer?
Posted: Wed Apr 08, 2009 1:52 pm
by axtens
Kazimir Majorinc wrote:I think you are progressing quite good. Are you experienced programmer?
Yes, just not in Lisp. I've been in the IT business in various ways since 1983. At the moment I'm working for
The Protium Project and
MyTongue as a Software/Test Engineer. I program in a variety of languages, including Ada, assembler, (Visual) BASIC, C/C++, Delphi, Fortran, Perl, Protium, Tcl, and VBScript (and a few lesser known languages.)
Kind regards,
Bruce.